Extract text with linebreaks

Hi,


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.

Thanks

Hi Sri,


Thank you for contacting Aspose support.

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”);

Hi again,

babar.raza:
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");

I found a better way. I have made one change to my existing code:


var cellValue = cell.DisplayStringValue;

with

var cellValue = cell.DisplayStringValue.Replace("\n", “\v”);

now w:br node/manual line break is automatically added. :slight_smile:

Hi Sri,


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.