Hi All,
Hi,
Thanks a lot. It’s working now.
Hi,
Hi,
Hi,
Thanks for the template file.
Please try our latest version/fix: Aspose.Cells for Java (Latest Version)
I have tested using your template file with the following sample code, it shows correct page count:
e.g
Sample code:
Workbook workbook = new Workbook(“PAGECount.xlsx”);
Worksheet worksheet = workbook.getWorksheets().get(1);
ImageOrPrintOptions printoption = new ImageOrPrintOptions();
printoption.setPrintingPage(PrintingPageType.DEFAULT);
SheetRender sr = new SheetRender(worksheet, printoption);
int pageCount = sr.getPageCount();
System.out.println(pageCount);
CellArea [] area = worksheet.getPrintingPageBreaks(printoption);
System.out.println(area.length);
Let us know if you still find the issue with latest version/fix v8.6.0.3.
Thank you.
Hi Amjad,
What we are doing
we are creating Template first
then calculate the page count.
then save the file
Below is the sample code.
Worksheet worksheet=workbook.getWorksheets().get(1);
Cells cells = worksheet.getCells();
cells.insertRows(,)
ImageOrPrintOptions printoption =
new ImageOrPrintOptions();
printoption.setPrintingPage(PrintingPageType.
DEFAULT);
SheetRender sheetRender =
new SheetRender(worksheet, printoption);
pageCount+= sheetRender.getPageCount();
we save workbook in last
workbook.save()
Does above process have different result?
we are facing this issue when there are more than 800 rows. for 100-200 rows there is no issue.
Kindly help
Hi,
Hi,
Below is code snippet the similar thing I am doing in my application.
result of Page count via code and in print preview, is different. Please find the input and output file in attachment
import com.aspose.cells.Cells;
import com.aspose.cells.ImageOrPrintOptions;
import com.aspose.cells.PrintingPageType;
import com.aspose.cells.SheetRender;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
public class TestPrintOption {
public static void main(String[] args) throws Exception {
Workbook workbook=new Workbook("C:\\test\\TestPrintOption.xlsx");
Worksheet worksheet = workbook.getWorksheets().get(0);
Workbook outputWorkbook = new Workbook();
Worksheet outputWorkSheet = outputWorkbook.getWorksheets().get(0);
outputWorkSheet.copy(worksheet);
Cells cells = outputWorkSheet.getCells();
cells.insertRows(1, 10000);
for(int i=1;i<=10000;i++) {
cells.copyRow(cells, 0, i);
}
cells.deleteRows(1, 20);
ImageOrPrintOptions printoption = new ImageOrPrintOptions();
printoption.setPrintingPage(PrintingPageType.DEFAULT);
SheetRender sheetRender = new SheetRender(outputWorkSheet, printoption);
System.out.println(sheetRender.getPageCount());
outputWorkbook.save("C:\\test\\TestPrintOption_output.xlsx");
}
}
Hi Tauqeer,
Hi again,
Worksheet worksheet = workbook.getWorksheets().get(0);
Workbook outputWorkbook = new Workbook();
Worksheet outputWorkSheet = outputWorkbook.getWorksheets().get(0);
outputWorkSheet.copy(worksheet);
Cells cells = outputWorkSheet.getCells();
cells.insertRows(1, 10000);
for(int i=1;i<=10000;i++) {
cells.copyRow(cells, 0, i);
}
cells.deleteRows(1, 20);
ImageOrPrintOptions printoption = new ImageOrPrintOptions();
printoption.setPrintingPage(PrintingPageType.DEFAULT);
//autofit rows(only row height is auto)
System.out.println(outputWorkSheet.getCells().getRowHeight(0));
outputWorkSheet.autoFitRows(true);
System.out.println(outputWorkSheet.getCells().getRowHeight(0));
SheetRender sheetRender = new SheetRender(outputWorkSheet, printoption);
System.out.println(sheetRender.getPageCount());
outputWorkbook.save(“D:/TestPrintOption_output.xlsx”);
Hi Team,
Hi Tauqeer,
Hi again,
Hi Tauqeer,
Hi again,
I am facing the same problem again , not getting proper page count. Below is my code snippet.
Result page count conflicit
1.Java api show page count output 1278 pages.
2.whereas Print preview is showing 1135 pages
Workbook workbook=new Workbook(“C:\test\Test.xlsx”);
Worksheet worksheet = workbook.getWorksheets().get(0);
Workbook outputWorkbook = new Workbook();
Worksheet outputWorkSheet = outputWorkbook.getWorksheets().get(0);
outputWorkSheet.copy(worksheet);
Cells cells = outputWorkSheet.getCells();
//cells.insertRows(1, 10000);
for(int i=1;i<=10000;i++) {
cells.copyRow(cells, 0, i);
}
cells.deleteRows(1, 20);
ImageOrPrintOptions printoption = new ImageOrPrintOptions();
printoption.setPrintingPage(PrintingPageType.DEFAULT);
//printoption.setAllColumnsInOnePagePerSheet(true);
//autofit rows(only row height is auto)
System.out.println(outputWorkSheet.getCells().getRowHeight(0));
outputWorkSheet.autoFitRows(true);
System.out.println(outputWorkSheet.getCells().getRowHeight(0));
SheetRender sheetRender = new SheetRender(outputWorkSheet, printoption);
System.out.println(sheetRender.getPageCount());
outputWorkbook.save(“C:\test\Test_output.xlsx”);
Please let me know if I am making any mistake. I run this program with aspose-cells-8.3.2.jar and aspose-cells-8.7.0.jar both. Please find output file in attachment
Hi,
hi