Hi,
I am trying to do something as follows, but it doesn't appear, but images are not in the exported excel file.
string html = "
Welcome to the HTML editor!
Just type the HTML and it will be shown below.
Header 1 | Header 2 |
1.2344 | 23% |
4444 | 345.34 |
![\"test\"]()
";
webBrowser1.NavigateToString(html);
Aspose.Cells.LoadOptions loadOptions = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Html);
System.IO.Stream stream = new System.IO.MemoryStream(ASCIIEncoding.Default.GetBytes(html));
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(stream, loadOptions);
wb.Save("c:\\temp\\AsposeCellsExport.xlsx", Aspose.Cells.SaveFormat.Xlsx);
Well actually I did get it to kind of work, but the output isn't what I'd expect exactly.
In my html if I have
The xls looks like the following, where the Image overlaps part of the last row of the first table and then the 2nd table starts right behind the image. Is there anything that can be put in the HTML so that it won't put any new data until after an image?
I have attached an example HTML created with the following source code:
string html = "
Welcome to the HTML editor!
Just type the HTML and it will be shown below.
Header 1 | Header 2 |
1.2344 | 23% |
4444 | 345.34 |
Header 1 | Header 2 |
1.2344 | 23% |
4444 | 345.34 |
";
webBrowser1.NavigateToString(html);
Aspose.Cells.LoadOptions loadOptions = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Html);
System.IO.Stream stream = new System.IO.MemoryStream(ASCIIEncoding.Default.GetBytes(html));
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(stream, loadOptions);
wb.Save("c:\\temp\\AsposeCellsExport.xlsx", Aspose.Cells.SaveFormat.Xlsx);
stream.Close();
Thanks
Hi,
Thanks for using Aspose.Cells for .NET.
Well, HTML to Xls is not supported fully and you cannot convert any type of html to xls, you can only convert the html which is generated by Ms-Excel.
So, please restrict your html tags to the one used by Ms-Excel.
I would suggest you to use image uri(s) instead of image links. This way you could embed your images.
Please see the code below. It embeds one such image into html and then convert it into xls. I have attached the source image, output xls file and the screenshot for your reference.
C#
string imgFile = @“D:\Documents and Settings\AHome\Desktop\banner-aspose-cells-
for-net.jpg”;
byte[] imgBytes = File.ReadAllBytes(imgFile);
string imgString = Convert.ToBase64String(imgBytes);
// input
string html = @"
# |
Property |
Name |
Value |
Sky |
Blue |
![]() |
Year |
2012 |
images comes above |
EUR-USD |
1.3275 |
Date |
2/8/2012 |
Time |
10:10:10 AM |
";
html = html.Replace("EMBEDDEDIMAGE", imgString);
// aspose XLS prep
byte[] byteArray = Encoding.ASCII.GetBytes(html);
MemoryStream stream =
new MemoryStream(byteArray);
Aspose.Cells.LoadOptions loadOptions =
new Aspose.Cells.LoadOptions(LoadFormat.Html);
Workbook workbook =
new Workbook(stream, loadOptions);
workbook.Save("output.xls", SaveFormat.Excel97To2003);
Source Image and Screenshot:
Hi,
I'm still able to get exactly what I was hoping for. Not sure if it's my HTML and or just a limitation of the control.
string imgFieldFile = @"C:\temp\TestParticleField.PNG";
byte[] imgBytes = System.IO.File.ReadAllBytes(imgFieldFile);
string imgString = Convert.ToBase64String(imgBytes);
string html = @"
Welcome to the HTML editor!</h2? |
Header 1 | Header 2 | 1.2344 |
23% | 4444 | 345.34 | |
|
Header 1 | Header 2 | 1.2344 |
23% | 4444 | 345.34 | |
";
html = html.Replace("EMBEDDEDIMAGE", imgString);
webBrowser1.NavigateToString(html);
byte[] byteArray = Encoding.ASCII.GetBytes(html);
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray))
{
Aspose.Cells.LoadOptions lo = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Html);
Aspose.Cells.Workbook workBook = new Aspose.Cells.Workbook(stream, lo);
workBook.Save("c:\\temp\\AsposeCellsExport.xlsx", Aspose.Cells.SaveFormat.Xlsx);
}
Attached are my output XLSX and screenshot.
Let me know what I may be doing wrong.
Thanks,
David
Hi,
After running your code. I got the attached output xlsx file.
Please check. Let me know your expected output xlsx file you can create one manually using Ms-Excel 2010.
C#
string imgFieldFile = @“D:\Documents and Settings\AHome\Desktop\stop.jpg”;
byte[] imgBytes = System.IO.File.ReadAllBytes(imgFieldFile);
string imgString = Convert.ToBase64String(imgBytes);
string html = @"
Welcome to the HTML editor!</h2? |
<table border="“1"”> |
Header 1 | Header 2 |
1.2344 |
23% |
4444 | 345.34 |
<img src="“data:image/png;base64,EMBEDDEDIMAGE”"> <table border="“1"”>
Header 1 Header 2 1.2344
23% 4444 345.34 ";
html = html.Replace(“EMBEDDEDIMAGE”, imgString);
byte[] byteArray = Encoding.ASCII.GetBytes(html);
using (System.IO.MemoryStream stream =
new System.IO.MemoryStream(byteArray))
{
Aspose.Cells.LoadOptions lo =
new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Html);
Aspose.Cells.Workbook workBook =
new Aspose.Cells.Workbook(stream, lo);
workBook.Save(“F:\Shak-Data-RW\Downloads\AsposeCellsExport.xlsx”, Aspose.Cells.SaveFormat.Xlsx);
}
Screenshot:
Hi I beleive that there is another table of data behind the image.
Attached is an XLSX that I'm expecting, AsposeCellsExport_EXPECTED.xlsx
Hi,
Thanks for your elaboration.
Yes, you can think of it as a limitation of Aspose.Cells. But the same limitation exists for Ms-Excel too.
Actually, when you export your expected xlsx file into html format, you will see, Ms-Excel has added so many empty td and tr tags to cover the area of picture.
So, you will have to modify your html in such a way that enough number of empty rows could be inserted in your exported xls/xlsx workbook so that rest of your data should come after your image not behind your image.