Convert XML to word (Nalb4242)

Hello I am trying to output xml file to be saved in word table …
when trying to convert xml to word the table is cropped and columns are in different pages not all in same .
I managed to convert the xml to excel sheet and try to take image of the whole table and add them to word or convert excel to pdf or word but always same problem … so how can i take add the whole table even screen shot of the table as all not splitted ??

@Nalb4242 Could yo please attach your input file, output and expected documents, along with your code? We will check the issue and provide you more information.

Hello ,

As you can see i Converted from xml to Excel in TestExcel which I have in it multiple columns after that i tried to convert the excel sheet to word in TestDoc as you can see in TestDoc columns are splited all over the document which is not what I want … I wanna do as in the TargetDoc (screen shots of the whole table it can split the row it is ok with me but not the columns as they are not readable )
I even tried to take screen shots to the excel but even that split the column

you will find the Files I am taking about and the Code I use too ,

Please I need Help asap.

Thank YouDocumentFiles.7z (105.1 KB)

@Nalb4242,

Thanks for the sample files and code snippets.

I checked and found you are using Aspose.Cells to import XML data into the spreadsheet and then convert to DOCX. If you could take the print preview of the sheet “Sheet1” in MS Excel manually, you will also notice that it splits to multiple pages as per your output DOCX by Aspose.Cells, so it is not an issue with the APIs. For your requirements, you may set Fit to Pages option accordingly before rendering to DOCX. See the sample code which works fine as I tested. I have also applied auto-fit columns operation to your data (first) in code so it does not necessarily extend the columns width.
e.g.
Sample code:

// Open the Excel file
Workbook workbook = new Workbook("g:\\test2\\TestExcel.xlsx");

// Auto-fit columns in the worksheet
workbook.Worksheets["Sheet1"].AutoFitColumns();
            
PageSetup pageSetup = workbook.Worksheets["Sheet1"].PageSetup;
pageSetup.SetFitToPages(1, 0);
            
// Save as DOCX
workbook.Save("g:\\test2\\out1.docx", Aspose.Cells.SaveFormat.Docx);

PS. please try latest (available) version of Aspose.Cells for .NET if you are not already using it.

hello ,

I have tried the previous code … but i do not know why i am getting the below output.

c1.PNG (9.2 KB)

@Nalb4242,

Did you try my suggested code with your (previously attached) file. Please paste your working code here. Also, zip and attach your template Excel file if it is different than what you previously attached in the post. We will check your issue soon.

PS. please find attached the output DOCX file generated on my end using your Excel file and with my sample code for your reference.
out1.zip (9.7 KB)

Hello ,

I have discovered what is wrong it outputs the right answer but my problem is my last column is description and it has a long data …

is there a way to not include the last column before converting excel to word ?

Thank you

@Nalb4242,

You may set print area to specify your desired range of cells to be rendered (you may skip last (long) column), see the document with example code for your reference.

1 Like