I am trying to extract text from excel file. Herewith I have attached the source excel file and expected output word file. I am not sure how to extract the linebreaks from excel file.
If you wish to get the text from a spreadsheet cell in same formatting & layout then please use the Cell.HtmlString property. You can inject the Html acquired from Cell.HtmlString to the word document as demonstrated below. Please note, I am not able insert the space between the 2 paragraphs therefore please create a thread in Aspose.Words support forum with code, expected results and requirement in case the space is mandatory.
C#
var doc = new Aspose.Words.Document(); var builder = new Aspose.Words.DocumentBuilder(doc); var book = new Aspose.Cells.Workbook(fileName); IEnumerator cellEnumerator = book.Worksheets[0].Cells.GetEnumerator(); while (cellEnumerator.MoveNext()) { var cell = cellEnumerator.Current as Aspose.Cells.Cell; string html = cell.HtmlString; if (html != string.Empty) { builder.InsertHtml(html); } builder.InsertBreak(Aspose.Words.BreakType.ParagraphBreak); } doc.Save(dir + “output.doc”);
Please note, I am not able insert the space between the 2 paragraphs therefore please create a thread in Aspose.Words support forum with code, expected results and requirement in case the space is mandatory.
I have discussed the above mentioned issue with the experts of Aspose.Words, and we are able to resolve it by adjusting the space between the paragraphs. Please check the updated code segment as well as the resultant document.
C#
var doc = new Aspose.Words.Document(); var para = (Aspose.Words.Paragraph)doc.GetChild(Aspose.Words.NodeType.Paragraph, 0, true); para.ParagraphFormat.SpaceAfter = 8; var builder = new Aspose.Words.DocumentBuilder(doc); var book = new Aspose.Cells.Workbook(fileName); IEnumerator cellEnumerator = book.Worksheets[0].Cells.GetEnumerator(); while (cellEnumerator.MoveNext()) { var cell = cellEnumerator.Current as Aspose.Cells.Cell; string html = cell.HtmlString; if (html != string.Empty) { builder.InsertHtml(html, true); } builder.InsertBreak(Aspose.Words.BreakType.ParagraphBreak); } doc.Save(dir + "output2.doc");
Thank you for suggesting another solution for the said scenario. It will be helpful for other community users having similar requirements. Please feel free to contact us back in case you need our further assistance with Aspose APIs.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.