2

i've made a program in c# In order to print an excel file, he print it fine, but also all grid. But I don't want to see the grid.

I've done this :

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

Don't pay attention to comments, I'm french.

3
  • Have you tried ws.PageSetup.PrintGridlines = false; instead of ws.PageSetup.PrintGridlines = true;? Commented Apr 7, 2015 at 11:03
  • 1
    Omg ! Thank you it works. I forgot this line... Commented Apr 7, 2015 at 11:29
  • I'm going to turn this into an answer so you can accept. Commented Apr 7, 2015 at 11:30

1 Answer 1

2

Try setting

ws.PageSetup.PrintGridlines = false; 

instead of

ws.PageSetup.PrintGridlines = true;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.