DsExcel Java allows users to specify the page range while printing a worksheet.
In order to configure page range for the print operation, refer to the following example code.
Java |
Copy Code |
---|---|
// Create a new workbook and access the default worksheet Workbook workbook = new Workbook(); IWorksheet sheet = workbook.getWorksheets().get(0); // Set pages' data. sheet.getRange("A1:J46").setValue("Page1"); sheet.getRange("A1:J46").getInterior().setColor(Color.GetLightGreen()); sheet.getRange("A47:J92").setValue("Page2"); sheet.getRange("A47:J92").getInterior().setColor(Color.GetLightYellow()); sheet.getRange("K1:T46").setValue("Page3"); sheet.getRange("K1:T46").getInterior().setColor(Color.GetOrangeRed()); sheet.getRange("K47:T92").setValue("Page4"); sheet.getRange("K47:T92").getInterior().setColor(Color.GetDarkOrange()); sheet.getRange("U1:AD46").setValue("Page5"); sheet.getRange("U1:AD46").getInterior().setColor(Color.GetLightBlue()); sheet.getRange("U47:AD92").setValue("Page6"); sheet.getRange("U47:AD92").getInterior().setColor(Color.GetIndianRed()); sheet.getPageSetup().setPrintHeadings(true); // Set print page range, print p1, p3 to p5. sheet.getPageSetup().setPrintPageRange("1,3-5"); // Save to a pdf file workbook.save("PrintPageRange.pdf", SaveFileFormat.Pdf); |