Excel to word conversion

Hi,
I have basic question, is it possible to convert an excel file to a word document using aspose. If so, can you provide some sample code,
thanks,
Brian

This message was posted using Aspose.Live 2 Forum

Hi,

Well, I am afraid, there is no such feature (directly convert excel file to word doc) available at the moment. Although Aspose.Cells for .NET does provide Worksheet to Image and Excel 2 PDF features, so, you may take the images/pictures of the worksheets using Aspose.Cells API and paste it in word document using Aspose.Words API, not sure if it suit your need.

Thank you.

Hi,

Thanks for your reply.
Using an image of the excel worksheet is an option, however the linked code will not compile.
I am using the latest versions of aspose cells and words. Here is the code I am using, followed by the compilation errors,

for (int frameIdx = 0; frameIdx <framesCount; frameIdx++)
{
    // Insert a section break before each new page, in case of a multi-frame TIFF.
    if (frameIdx != 0)
        builder.InsertBreak(BreakType.SectionBreakNewPage);
    // Select active frame
    image.SelectActiveFrame(FrameDimension.Page, frameIdx);
    // We want the size of the page to be the same as the size of the image.
    // Convert pixels to points to size the page to the actual image size.
    Aspose.Words.PageSetup ps = builder.PageSetup;
    ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
    ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);
    // Insert the image into the document and position it at the top left corner of the page.
    builder.InsertImage(image, RelativeHorizontalPosition.Page, 0, RelativeVerticalPosition.Page, 0,ps.PageWidth, ps.PageHeight, WrapType.None);
}

The name’ ConvertUtil’ does not exist in the current context

No overload for method ‘InsertImage’ takes ‘8’ arguments

Hi,

I will move this thread to Aspose.Words forum, so they can look into your issue and help you soon.

Thank you.

Hi

Thanks for your interest in Aspose products. There is a demo project which allows converting Excel to Word using Aspose.Words+Aspose.Cells. You can find this project here:
https://releases.aspose.com/words/net
If you are still facing the problems, please attach your Excel Workbook and code, which will allow us to reproduce the problem.
Best regards,

Hi,

thanks again for your quick reply.
I have got around the above problem, just by using builder.InsertImage(image).
I have a different issue now though. I am generating a word doc from an in-memory html, however a the borders of the tables are not appearing in the generated word doc. Here is some sample html, is it supported?

</table>
<table width="100%">
   <tr>
      <td align="center" style="FONT-FAMILY:arial;FONT-SIZE:12pt;FONT-WEIGHT:bolder;text-decoration:underline; ">CUSTOMER INFORMATION</td>
   </tr>
</table>
<table width="100%" style="FONT-FAMILY:arial;FONT-SIZE:9pt; " cellpadding="3">
   <tr>
      <td width="20%" align="left"><font style="FONT-WEIGHT:bolder;">Type: </font> 
      </td>
      <td align="left"><font style="FONT-WEIGHT:bolder;">Multiple Use Factility?:</font></td>
   </tr>
   <tr>
      <td align="left"><font style="FONT-WEIGHT:bolder;">NAICS#:</font>522202
      </td>
   </tr>
</table>

Hi

Thanks for your inquiry. As I can see there is no borders specified in your HTML. If you need to display borders, you should specify them. For example, see the following HTML:

<html>
<body>
    <table width="100%" border="1">
        <tr>
            <td align="center" style="FONT-FAMILY:arial;FONT-SIZE:12pt;FONT-WEIGHT:bolder;text-decoration:underline; ">CUSTOMER INFORMATION</td>
        </tr>
    </table><br><table width="100%" style="FONT-FAMILY:arial;FONT-SIZE:9pt; " cellpadding="3" border="1">
        <tr>
            <td width="20%" align="left">
                <font style="FONT-WEIGHT:bolder;">Type: </font>
            </td>
            <td align="left"><font style="FONT-WEIGHT:bolder;">Multiple Use Factility?:</font></td>
        </tr>
        <tr>
            <td align="left">
                <font style="FONT-WEIGHT:bolder;">NAICS#:</font>522202
            </td>
        </tr>
    </table>
</body>
</html>

Best regards,

Hi,

Sorry bad example!
Here is another table I am using. As you can see I am setting the border to 1.
I think Aspose Java does not support inline css, does Aspose Net?

Do you a link to sample code for inserting an image into a word file.
The sample i have uses ConvertUtil which does not seem to be in the latest version of Aspose.Words.

Also, I need to insert some some html thats in a word file into a new word file. but am getting this exception, followed by the code (the exception occurs when i save the doc):
“Unicode surrogate characters must be written out as pairs together in the same call, not individually. Consider passing in a character array instead.”

StreamReader reader = new StreamReader(m_subPdf + ".doc");
string contents = reader.ReadToEnd();
reader.Close();
builder.InsertHtml(contents);

thanks,

Brian

<table width="100%" style="border:1px solid black;FONT-FAMILY:arial;FONT-SIZE:9pt;" cellpadding="3" cellspacing="0">
   <tr bgcolor="#E0E0E0">
      <td align="left" colspan="6" style="border-bottom:1px solid black;FONT-WEIGHT:bolder;text-decoration:underline;">A. Commission / Fronting Fees:</td>
   </tr>
   <tr>
      <td align="left" colspan="6" style="FONT-WEIGHT:bolder;text-decoration:underline;">If Per Annum Basis Fees:</td>
   </tr>
   <tr>
      <td width="15%" align="left" style="FONT-FAMILY:arial; FONT-SIZE:9pt; FONT-WEIGHT:bolder;">Percentage Rate:</td>
      <td align="left"></td>
      <td width="15%" align="left" style="FONT-FAMILY:arial; FONT-SIZE:9pt; FONT-WEIGHT:bolder;">Minimum Commission:</td>
      <td align="left"></td>
      <td width="15%" align="left" style="FONT-FAMILY:arial; FONT-SIZE:9pt; FONT-WEIGHT:bolder;">Minimum Per Annum Charge:</td>
      <td width="15%" align="left"></td>
   </tr>

Hi

Thank you for additional information. The problem occurs because CSS styles are not fully supported on table, tr, td and th nodes on import. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.
Best regards,

Hi,

I am using the code below to insert an image into a document. However, the image is corrupting the document after it is inserted, when I open the resultant document, the layout has been set to landscape and the page size is set to very small 10cmX10 cm or so. Anyone have any ideas on how to fix this?
Note the problem occurs even when there is nothing else added to the document (and if I add text only and no image, then the document is fine)

thanks,

Brian

private void InsertImageToWordDocument(DocumentBuilder builder, string imagePath)
{
    Image image = Image.FromFile(imagePath);
    // Get the number of frames in the image.
    int framesCount = image.GetFrameCount(FrameDimension.Page);
    // Loop through all frames
    for (int frameIdx = 0; frameIdx <framesCount; frameIdx++)
    {
        // Insert a section break before each new page, in case of a multi-frame TIFF.
        if (frameIdx != 0)
            builder.InsertBreak(BreakType.SectionBreakNewPage);
        // Select active frame
        image.SelectActiveFrame(FrameDimension.Page, frameIdx);
        // We want the size of the page to be the same as the size of the image.
        // Convert pixels to points to size the page to the actual image size.
        Aspose.Words.PageSetup ps = builder.PageSetup;
        ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
        ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);
        // Insert the image into the document and position it at the top left corner of the page.
        // builder.InsertImage(image, 0, 0, 0,
        // 0,ps.PageWidth, ps.PageHeight, 0);
        // builder.InsertBreak(BreakType.SectionBreakNewPage);
        builder.InsertImage(image);
    }
    image.Dispose();
}

Hi

Thanks for your inquiry. This occurs because in your code you resize pages to the size of your image. Please see the highlighted code:

private void InsertImageToWordDocument(DocumentBuilder builder, string imagePath)
{
    Image image = Image.FromFile(imagePath);
    // Get the number of frames in the image.
    int framesCount = image.GetFrameCount(FrameDimension.Page);
    // Loop through all frames
    for (int frameIdx = 0; frameIdx <framesCount; frameIdx++)
    {
        // Insert a section break before each new page, in case of a multi-frame TIFF.
        if (frameIdx != 0)
            builder.InsertBreak(BreakType.SectionBreakNewPage);
        // Select active frame
        image.SelectActiveFrame(FrameDimension.Page, frameIdx);
        // We want the size of the page to be the same as the size of the image.
        // Convert pixels to points to size the page to the actual image size.
        Aspose.Words.PageSetup ps = builder.PageSetup;
        ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
        ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);
        // Insert the image into the document and position it at the top left corner of the page.
        // builder.InsertImage(image, 0, 0, 0,
        // 0,ps.PageWidth, ps.PageHeight, 0);
        // builder.InsertBreak(BreakType.SectionBreakNewPage);
        builder.InsertImage(image);
    }
    image.Dispose();
}

If just need to insert an image into a document, you do not need all this code, you can just use one line of code: builder.InsertImage(image);
Best regards,

The issues you have found earlier (filed as WORDSNET-3163) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(43)