Set Custom Height Width In ASpose.Cell

Hello Team,

We are doing Image export for each worksheet as one page , here we can able to mange setting different pagesize like A4,legal,Letter etc…

But not getting any option to set Custom Pagesize where user provides any Height and Width to set .
PageSetup.PageHeight this are readonly property.

Can you guide how to set custom user input height and width for aspose.cell .

Thanks

@Viral84

To set a custom page size in Aspose.Cells, you can utilize the PageSetup class to define the height and width of the page. Although the PageHeight and PageWidth properties are read-only, you can achieve your goal by setting the PaperSize to PaperSizeType.CUSTOM and then specifying the dimensions using the setCustomPaperSize method.

Here’s a code snippet to illustrate how to set a custom page size:

Workbook workbook = new Workbook("your_file.xlsx");
Worksheet sheet = workbook.getWorksheets().get(0); // Get the first worksheet

PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setPaperSize(PaperSizeType.CUSTOM); // Set to custom paper size

// Set custom width and height in inches
double customWidth = 8.5; // Example: 8.5 inches
double customHeight = 11.0; // Example: 11.0 inches
pageSetup.setCustomPaperSize(customWidth, customHeight);

// Save the workbook
workbook.save("output_file.pdf", SaveFormat.PDF);

In this example, replace your_file.xlsx with the path to your Excel file and adjust customWidth and customHeight to the desired dimensions. This will allow you to export the worksheet with the specified custom page size.

For further information, please consult the official Aspose.Cells documentation.

Thank you so much this suggested code works fine.

@Viral84,

We are glad to hear that the suggested method PageSetup.CustomPaperSize(width, height) meets your requirements effectively. Should you have any further questions or comments, please do not hesitate to reach out to us at any time. We would be more than happy to assist you soon.