Hi,
We working with Aspose.Cells, Version=23.5.0.0.
We trying to load html content to workbook and preserve the design as is
.
Any idea how we can achieve that? I tried to search with Claude but I don’t see option that valid to our version. maybe you have some insight for that?
if this is matter - we need to load the data from html to the workbook and save it to xlsx file of pdf.
but the design should remain the same.
this is my code for loading the html content to workbook.
public async Task<Workbook> RenderHtmlWorkBookAsync(string html)
{
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(html);
var lo = new HtmlLoadOptions(LoadFormat.Html)
{
ConvertNumericData = false
};
using (var stream = new MemoryStream(byteArray))
{
return await Task.FromResult(new Workbook(stream, lo));
}
}
that called from:
// Use the new rendering method based on flags
string html = await RenderHtmlTemplateAsync(formattedJson, htmlTemplate, flags?.ShouldUseExternalHtmlRenderer ?? false);
var workbook = await asposeHelper.RenderHtmlWorkBookAsync(html);
var designer = new WorkbookDesigner(workbook)
{
LineByLine = false
};
var activeWorksheet = designer.Workbook.Worksheets[designer.Workbook.Worksheets.ActiveSheetIndex];
if (!ignoreLogo)
{
activeWorksheet.Cells["A2"].PutValue("&=$logo(Picture:Scale20)");
designer.SetDataSource("logo", logo);
}
designer.Process();
designer.Workbook.Settings.Author = "JET";
return await asposeHelper.SaveToStreamAsync(designer, fileFormat);
save to stream:
public async Task<byte[]> SaveToStreamAsync(WorkbookDesigner designer, FileFormat fileFormat)
{
using (var stream = new MemoryStream())
{
switch (fileFormat)
{
case FileFormat.PDF:
var pdfSaveOptions = GetPdfSaveOption();
designer.Workbook.Save(stream, pdfSaveOptions);
break;
case FileFormat.EXCEL:
designer.Workbook.Save(stream, SaveFormat.Xlsx);
break;
}
return await Task.FromResult(stream.ToArray());
}
}
private PdfSaveOptions GetPdfSaveOption()
{
return new PdfSaveOptions
{
OptimizationType = PdfOptimizationType.MinimumSize,
AllColumnsInOnePagePerSheet = true,
ExportDocumentStructure = true
};
}