Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.
Thu Nov 29, 2018 2:48 am
Hi Guys,
I have a excel file whit 4 sheets (Worksheet) inside.
When try to print the file always print the first worksheet (sheet1), my question is... how can I print the sheet you want for examen the sheet3?
this is my code (c#):
- Code: Select all
Workbook excel = new Workbook();
excel.LoadFromFile(@"c:\test.xlsx");
excel.PrintDocument.PrinterSettings.Duplex = Duplex.Simplex;
excel.PrintDocument.PrinterSettings.FromPage = 1;
excel.PrintDocument.PrinterSettings.ToPage = 1;
excel.PrintDocument.PrinterSettings.PrintRange = PrintRange.SomePages;
excel.PrintDocument.PrinterSettings.Copies = 1;
excel.PrintDocument.Print();
Thank You!
-
jmontero1980
-
- Posts: 2
- Joined: Thu Nov 29, 2018 2:38 am
Thu Nov 29, 2018 4:25 am
Hello,
Thank you for your inquiry.
To reach your goal, you could copy the sheet you want to print to a new Excel document and then print the new file.
Below is the code for your kind reference.
- Code: Select all
Workbook excel = new Workbook();
excel.LoadFromFile(path);
//get the sheet, eg, the third sheet
Worksheet desiredSheet = excel.Worksheets[2];
//copy the sheet you want to print to a new Excel.
Workbook newBook = new Workbook();
newBook.Version = ExcelVersion.Version2010;
newBook.Worksheets.Clear();
newBook.Worksheets.AddCopy(desiredSheet);
//print the new file
newBook.PrintDocument.PrinterSettings.Duplex = Duplex.Simplex;
newBook.PrintDocument.PrinterSettings.FromPage = 1;
newBook.PrintDocument.PrinterSettings.ToPage = 1;
newBook.PrintDocument.PrinterSettings.PrintRange = PrintRange.SomePages;
newBook.PrintDocument.PrinterSettings.Copies = 1;
newBook.PrintDocument.Print();
Sincerely,
Jane
E-iceblue support team
-
Jane.Bai
-
- Posts: 1156
- Joined: Tue Nov 29, 2016 1:47 am
Fri Nov 30, 2018 2:46 am
Hi Jane,
Thank you very much, for your time and help, i will try your solution and i will reply the result.
-
jmontero1980
-
- Posts: 2
- Joined: Thu Nov 29, 2018 2:38 am
Fri Nov 30, 2018 3:26 am
Hi,
Thank you for your reply.
Will look forward to your feedback.
Sincerely,
Jane
E-iceblue support team
-
Jane.Bai
-
- Posts: 1156
- Joined: Tue Nov 29, 2016 1:47 am
Mon Dec 03, 2018 6:17 am
Hi,
Greetings from e-iceblue!
How is the issue now?
Your feedback would be greatly appreciated!
Sincerely,
Jane
E-iceblue support team
-
Jane.Bai
-
- Posts: 1156
- Joined: Tue Nov 29, 2016 1:47 am