Hi,
We have taken an Aspose licence.We are trying to convert word
files to HTML. In these conversions, we have some files which contain
excel objects embedded within them. The issue is that the embedded excel
sheets are
converted to images. So I am not able to manipulate the content of
those excel sheets in the converted HTML file.
We are needed to replace the images with actual tables. Is that possible?
If not, the other approach we might take includes extracting and storing the excel tables as separate files and adding the name of the file in the converted HTML file. If you can suggest a way to work out any of the 2 approaches, it’ll be of great help.
Thanks and Regards,
Nikhil
Hi Nikhil,
Hi,
Thanks for your questions and using Aspose.
When Excel object is embedded inside the Word document, then Excel object is embedded as an Ole Object.
You can extract all types of Ole Objects from Word document using Aspose.Words.
Once, you will extract the Excel object as an Ole Object, you can then create a Workbook object of it using Aspose.Cells and manipulate it further.
In order to know how to extract Excel object as an Ole Object from your Word document, please post your query on Aspose.Words forum. Aspose.Words team will help you asap.
Hi Amjad & MShakeel,
Thanks for you quick reply. Will check out this approach and get back to you in case any help is required.
Regards,
Nikhil
Hi,
Thanks for your posting and considering Aspose.Cells.
Let us know if you face any issue relating to Aspose.Cells. We will be glad to help you asap.
Hello,Could you please provide me with a code snippet to extract information from an Excel shape and save it as an html file? I am trying the code below, but there seem to be some problem.
Aspose.Words.Document d = new Document(filename.ToString());
int i = 0;
//Save embedded excel as a separate file
NodeCollection shapes = d.GetChildNodes(NodeType.Shape, true);
foreach (Aspose.Words.Drawing.Shape shape in shapes)
{
if (shape.OleFormat.ProgId.Equals("Excel.Sheet.12"))
{
byte[] byteArr = Encoding.ASCII.GetBytes(shape.ToString());
MemoryStream stream = new MemoryStream(byteArr);
Aspose.Cells.Workbook newExcelDoc = new Aspose.Cells.Workbook(stream);
newExcelDoc.Save(destinationFileName + "_" + i);
++i;
}
}
HtmlSaveOptions htmlOptions = new HtmlSaveOptions(SaveFormat.Html);
d.Save(destinationFileName, htmlOptions);Aspose.Words.Document d = new Document(filename.ToString());
int i = 0;
//Save embedded excel as a separate file
NodeCollection shapes = d.GetChildNodes(NodeType.Shape, true);
foreach (Aspose.Words.Drawing.Shape shape in shapes)
{
if (shape.OleFormat.ProgId.Equals("Excel.Sheet.12"))
{
byte[] byteArr = Encoding.ASCII.GetBytes(shape.ToString());
MemoryStream stream = new MemoryStream(byteArr);
Aspose.Cells.Workbook newExcelDoc = new Aspose.Cells.Workbook(stream);
newExcelDoc.Save(Destinationfilename + "_" + i);
++i;
}
}
HtmlSaveOptions htmlOptions = new HtmlSaveOptions(SaveFormat.Html);
d.Save(Destinationfilename.ToString(), htmlOptions);
Hi,
I'm sorry but I have already asked their help and they had redirected me to the Cells team.
We have trusted Aspose and now we are at a critical stage. So please help me out instead of pushing the responsibility on other teams.
Thanks,
Nikhil
Hi,
Hi,
There are three issues in your code:
a) Getting ole object from ole object with Aspose.Words.
b) Saving the file to html file with Aspose.Cells.
c) There is no relation between the image and exported html.
Please check the following codes with the attached file.
string filename = @"D:\FileTemp\oleobject.docx";
string destinationFileName = @"D:\FileTemp\dest.html";
Aspose.Words.Document d = new Document(filename.ToString());
int i = 0;
//Save embedded excel as a separate file
NodeCollection shapes = d.GetChildNodes(NodeType.Shape, true);
foreach (Aspose.Words.Drawing.Shape shape in shapes)
{
if (shape.OleFormat.ProgId.Equals("Excel.Sheet.12"))
{
//a) Getting ole object from ole object with Aspose.Words.
MemoryStream stream = new MemoryStream();
shape.OleFormat.Save(stream);
stream.Seek(0, SeekOrigin.Begin);
//b) Saving the file to html file with Aspose.Cells.
Aspose.Cells.Workbook newExcelDoc = new Aspose.Cells.Workbook(stream);
Aspose.Cells.HtmlSaveOptions hOptions = new Aspose.Cells.HtmlSaveOptions();
newExcelDoc.Save(destinationFileName + "_" + i +".html", hOptions);
//c) There is no relation between the image and exported html.
shape.HRef = destinationFileName + "_" + i + ".html";
++i;
}
}
Aspose.Words.Saving.HtmlSaveOptions htmlOptions = new Aspose.Words.Saving.HtmlSaveOptions();
d.Save(destinationFileName, htmlOptions);
Hi Amjad,
Here is the code snippet suggested by the Words team. however, they have left the excel part for me to figure out. Can you please help me with this?
Document doc = new Document(@"C:\test\in.docx");
// Get collection of shapes
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
int i = 0;
//Loop through all shapes
foreach (Shape shape in shapes)
{
if (shape.OleFormat != null)
{
if (!shape.OleFormat.IsLink)
{
//Extract OLE Word object
if (shape.OleFormat.ProgId == "Word.Document.12")
{
MemoryStream stream = new MemoryStream();
shape.OleFormat.Save(stream);
Document newDoc = new Document(stream);
newDoc.Save(string.Format(@"C:\test\outEmbeded_{0}.html", i));
i++;
}
//Extract OLE Excel object
if (shape.OleFormat.ProgId == "Excel.Sheet.12")
{
// Here you can use Aspose.Cells component
// to be able to convert MS Excel files to separate HTML files
}
}
}
}
Document doc = new Document(@"C:\test\in.docx");
// Get collection of shapes
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
int i = 0;
//Loop through all shapes
foreach (Shape shape in shapes)
{
if (shape.OleFormat != null)
{
if (!shape.OleFormat.IsLink)
{
//Extract OLE Word object
if (shape.OleFormat.ProgId == "Word.Document.12")
{
MemoryStream stream = new MemoryStream();
shape.OleFormat.Save(stream);
Document newDoc = new Document(stream);
newDoc.Save(string.Format(@"C:\test\outEmbeded_{0}.html", i));
i++;
}
//Extract OLE Excel object
if (shape.OleFormat.ProgId == "Excel.Sheet.12")
{
// Here you can use Aspose.Cells component
// to be able to convert MS Excel files to separate HTML files
}
}
}
}
doc.Save(@"C:\test\out.html");doc.Save(@"C:\test\out.html");
Hi Amjad,
Here is the code snippet suggested by the Words team. however, they have left the excel part for me to figure out. Can you please help me with this?
Document doc = new Document(@"C:\test\in.docx");
// Get collection of shapes
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
int i = 0;
//Loop through all shapes
foreach (Shape shape in shapes)
{
if (shape.OleFormat != null)
{
if (!shape.OleFormat.IsLink)
{
//Extract OLE Word object
if (shape.OleFormat.ProgId == "Word.Document.12")
{
MemoryStream stream = new MemoryStream();
shape.OleFormat.Save(stream);
Document newDoc = new Document(stream);
newDoc.Save(string.Format(@"C:\test\outEmbeded_{0}.html", i));
i++;
}
//Extract OLE Excel object
if (shape.OleFormat.ProgId == "Excel.Sheet.12")
{
// Here you can use Aspose.Cells component
// to be able to convert MS Excel files to separate HTML files
}
}
}
}
Document doc = new Document(@"C:\test\in.docx");
// Get collection of shapes
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
int i = 0;
//Loop through all shapes
foreach (Shape shape in shapes)
{
if (shape.OleFormat != null)
{
if (!shape.OleFormat.IsLink)
{
//Extract OLE Word object
if (shape.OleFormat.ProgId == "Word.Document.12")
{
MemoryStream stream = new MemoryStream();
shape.OleFormat.Save(stream);
Document newDoc = new Document(stream);
newDoc.Save(string.Format(@"C:\test\outEmbeded_{0}.html", i));
i++;
}
//Extract OLE Excel object
if (shape.OleFormat.ProgId == "Excel.Sheet.12")
{
// Here you can use Aspose.Cells component
// to be able to convert MS Excel files to separate HTML file
}
}
}
}
doc.Save(@"C:\test\out.html");doc.Save(@"C:\test\out.html");
There are 2 problems in this code.
-
I do not know whether the ‘Shape’ class belongs to Microsoft.Office.Interop.Excel or Aspose.Words.Drawing.Shape.
-
Once I get the Shape object, how can I extract the Excel sheet and save it to the file?
I’ll be thankful if you can resolve my doubts.
Thanks,
Nikhil
Hi Shakeel,
This is exactly what I needed, especially those lines you added in red. Thanks a tonne for your help.
Regards,
Nikhil
Hi Amjad,
Shakeel has resolved the problem. Will work on it and trouble you guys if I get stuck again. Thanks for the support.
Regards,
Nikhil
Hi,
Thanks for your feedback and using Aspose.
It’s good to know your issue is resolved now.
Let us know if you face any other issue, we will be glad to assist you further.
Hi Shakeel, As suggested, here is the code I am using to add a link to the image of the Excel sheet embedded in the word doc.
int i = 0;
foreach (Aspose.Words.Drawing.Shape shape in shapes)
{
if (null != shape.OleFormat && shape.OleFormat.ProgId.Equals("Excel.Sheet.12"))
{
MemoryStream stream = new MemoryStream();
shape.OleFormat.Save(stream);
stream.Seek(0, SeekOrigin.Begin);
Aspose.Cells.Workbook newExcelDoc = new Aspose.Cells.Workbook(stream);
destinationFilePath
= @“D:\Excel Embed Test\Output” + Destinationfilename +
“_” + i + “.html”;
newExcelDoc.Save(destinationFilePath);
shape.HRef
= destinationFilePath;
++i;
}
}
This works perfectly. The excel object is an image in the converted file, but since it’s href is set, clicking on it takes me to the excel file for modification.
However, the requirement is that I want to replace the image by the anchor tag. Is that possible? Could you please provide a code snippet for the same?
Thanks and regards,
Nikhil
Hi,
Thanks for your posting.
We think you should check this feature with Aspose.Words that how to process an ole object as an anchor tag.
Aspose.Cells can only convert the data of the ole object to html file if the embedded file is excel file. We cannot decide how to place the html file in the parent html (generated by Aspose.Words)
Hi Shakeel,
Thanks for the prompt reply. I will take up this issue with the Words team.
Thanks and regards,
Nikhil
Hi,
Thanks for using Aspose components
In case, you need any assistance relating to Aspose.Cells, please feel free to post on our forums.
We will be glad to assist you.
Have a good day.