Converting excel to word results in collapsed cells

Hello,

I’m trying to convert the attached excel (TestLayout.xlsx inside TestLayout.zip (34.7 KB)
) to word but the conversion seems to collapse all rows, hiding completely their content, as the image below shows:

image.png (51.0 KB)

I’m using the following code for the conversion:

> private void appendExcelDocument(Document wordDocument, MultipartFile file) {
>         try (ByteArrayOutputStream conversionStream = new ByteArrayOutputStream()){
>             // Load the Excel file
>             var workbook = new Workbook(new ByteArrayInputStream(file.getBytes()));
>             // For each sheet set up the page orientation and the cells size
>             for (int i = 0; i < workbook.getWorksheets().getCount(); i++ )
>             {
>                 workbook.getWorksheets().get(i).getPageSetup().setOrientation(PageOrientationType.LANDSCAPE);
>                 workbook.getWorksheets().get(i).getPageSetup().setFitToPagesWide(1);
>                 workbook.getWorksheets().get(i).getPageSetup().setFitToPagesTall(0);
>             }
>             // Create the output stream to save the Excel conversion to word
>             workbook.save(conversionStream, com.aspose.cells.SaveFormat.DOCX);
> 
>             var docAttachment = new Document(new ByteArrayInputStream(conversionStream.toByteArray()));
>             // Dont copy the footers/headers from the target document in case they are already defined
>             disableHeadersLink(docAttachment);
>             // Remove any "empty" paragraphs the document may have in the end
>             removeLastParagraph(docAttachment);
> 
>             List<Table> tables = Arrays.stream(docAttachment.getChildNodes(NodeType.TABLE, true).toArray())
>                     .filter(Table.class::isInstance)
>                     .map(Table.class::cast)
>                     .collect(Collectors.toList());
> 
>             for (Table table: tables) {
>                 table.autoFit(AutoFitBehavior.AUTO_FIT_TO_WINDOW);
>             }
> 
>             wordDocument.appendDocument(docAttachment, ImportFormatMode.KEEP_SOURCE_FORMATTING);
>         } catch (IOException e) {
>             throw new RuntimeException("Could not read content from file " + file.getName() + ". Error: " + e);
>         }
>         catch (Exception e) {
>             throw new RuntimeException("Could not create Aspose Excel document from file " + file.getName() + ". Error: " + e);
>         }
>     }
> 
> private void disableHeadersLink(Document wordDocument) {
>     // Disable headers/footers inheriting.
>     wordDocument.getFirstSection().getHeadersFooters().linkToPrevious(false);
> }
> 
> private void removeLastParagraph(Document wordDocument) {
>     // Get the last paragraph in the document.
>     Paragraph lastPara = wordDocument.getLastSection().getBody().getLastParagraph();
>     // Remove last run in the paragraph if it contains page break.
>     if (lastPara.getRuns().getCount() > 0)
>     {
>         Run lastRun = lastPara.getRuns().get(lastPara.getRuns().getCount() - 1);
>         if (lastRun.getText().equals(ControlChar.PAGE_BREAK))
>             lastRun.remove();
>     }
> }

As you can see I’m using AutoFitBehavior.AUTO_FIT_TO_WINDOW, but even so it seems that the rows do not adapt to their content.

Besides as you can see in the resulting word in the attachments (TestLayout.docx), not all columns of the Excel are visible. I understand that the excel contains many columns, but what would you advice here to better show the complete content in the final word?

Many thanks.Preformatted text

@m1tnick
We reproduced the issue as you mentioned. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSJAVA-45151

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@m1tnick
If you preview in Excel after printing one page wide, you will find that the displayed result is very small as in docx.
All column widths add up to 52 inches, so all data is compressed very small to fit on one page.
If you want to convert to docx, and the page has many columns, please don’t set fit to one page width。