打印 excel 文件 c#

Print excel file c#

我用c#写了一个程序 为了打印一个excel文件,他打印的很好,而且全是格子。但我不想看到网格。

我已经做到了:

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 = ":";
            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é !"; 

不看评论,我是法国人

尝试设置

ws.PageSetup.PrintGridlines = false; 

而不是

ws.PageSetup.PrintGridlines = true;