Excel转换到PDF的打印顺序

component: Java Excel API | products.aspose.com
我们使用了下面代码转换Excel到PDF,在一个sheet中,转换顺序可否水平读取页面?如下图:
p1, p2
p3, p4
p5, p6

目前的API内置是垂直读取,读到底部,然后从顶部读取,如下图
p1, p4
p2, p5
p3, p6

try (InputStream is = new ByteArrayInputStream(excelData);) {
			Workbook book = new Workbook(is, opts);
			book.save(os, SaveFormat.PDF);
		} catch (Exception ex) {
			log.error("Unable to convert excel workbook to PDF", ex);
		}

@meadking,
您能否共享输入和输出文件以及预期的输出文件以进行我们的分析。

1 Like

@meadking,

By the way, could you try setting the printing order before rendering to PDF file format if it makes any difference? See the sample code segment for your reference:
e.g.
Sample code:

//Get the first worksheet or you may get your desired sheet accordingly
Worksheet worksheet = book.getWorksheets().get(0);
PageSetup pagesetup = worksheet.getPageSetup();
pagesetup.setOrder(PrintOrderType.OVER_THEN_DOWN);
..........
1 Like

@Amjad_Sahi
Thank you Amjad_Sahi, that’s the feature I want.
Well, may I set the order in the workbook level? not in the worksheet level like below, too much code and looks not nice.

       book.getWorksheets().forEach(ws->{
			Worksheet worksheet = (Worksheet)ws;
			worksheet.getPageSetup().setOrder(PrintOrderType.OVER_THEN_DOWN);
	   });

@ ahsaniqbalsidiqui

Thanks, the original post shows the layout in the source file, the output file is a PDF contains the A4 pages in vertical layout.

谢谢,原来的问题里面是输入文件的排版布局,输出文件是A4大小的PDF,就是垂直布局的,从上到下的文件。

@meadking,

No, you have to iterate through each sheet to set the printing order.

Could you share the input Excel file, we will check it soon.

PS. please zip the file prior attaching.