2015-04-07 126 views
2

我已經在c#中製作了一個程序,爲了打印excel文件,他打印的很好,還打印了所有網格。但我不想看到網格。打印excel文件c#

我已經做到了這一點:

System.Windows.Forms.MessageBox.Show("Ok !", "Impression", MessageBoxButtons.OK); 
    //PrintDocument document = new PrintDocument(); 
    //document.DocumentName = file; 
    //document.Print(); 

      // On déclare l'application 
      Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application(); 

      // On ouvre un classeur XLS : 
      Microsoft.Office.Interop.Excel.Workbook wb = app.Workbooks.Open(chemin.Text, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing); 

      // On ouvre la première feuille : 
      // la numérotation commence à 1 et pas à 0 ici 
      Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[1]; 

      // Utiliser la Mise en page avec PageSetup 
      // Les entêtes de ligne et de colonne sont à répéter sur toutes les pages : 
      //ws.PageSetup.PrintTitleColumns = "$A:$B"; 
      //ws.PageSetup.PrintTitleRows = "$1:$2"; 
      ws.PageSetup.PrintHeadings = false; 
      ws.PageSetup.BlackAndWhite = false; 
      ws.PageSetup.PrintGridlines = true; 

      // Lancement de l'impression par défaut 
      ws.PrintOut(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); 

      // Afficher l’application Excel 
      app.Visible = false; 

      // Fermer l'application Excel 
      wb.Save(); 
      wb.Close(false, Type.Missing, Type.Missing); 
      app.Quit(); 

      // Réinitialise l'application 
      chemin.Text = "Imprimé !"; 

不要講究的意見,我是法國人。

+0

您是否嘗試過'ws.PageSetup.PrintGridlines = FALSE;',而不是'ws.PageSetup.PrintGridlines = TRUE;'? –

+1

Omg!謝謝你的作品。我忘了這條線...... – FlorianSL

+0

我打算把它變成一個答案,以便你可以接受。 –

回答

1

嘗試設置,而不是

ws.PageSetup.PrintGridlines = false; 

ws.PageSetup.PrintGridlines = true;