We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ConvertXls2Doc rendering issue

I am converting XLS files to DOC files using ConvertXLS2DOC. After the files is converted it looks correct in Preview Mode but in normal mode it has trouble rendering. The attached doc is has that problem. Can you tell me why this happens and what I can do to fix it?
Thanks for your help.
- John

Hi
Thanks for your inquiry. It seems the there is some issue in MS Word. When I set zoom to 150% the document looks fine. Could you please attach your source XLS file for testing? I will try to figure out why this occurs.
Best regards.

Alexey,
Thanks for your willingness to help.
I can’t exactly figure out where the source for the doc I sent you is. Attached to this reply is a matching xls and doc file with the same issue
- John

Hi
Thank you for additional information. I suppose you have modified the code of Xls2Doc converter. The output I got using original converter looks as expected. Attached is class I used for conversion.
Best regards.

Alexey,
Thank you for your response. It helped me find exactly where the problem is. (Yes I have my own version of the convertxls2doc class).
This is the code that caused the rendering issue. What I am trying to do is scale the print area in excel to fit the page in word. This requires that I scale both the width of the cells and the fonts of text in the tables. But the text is only accessible through the ‘Runs’. When I changed the font size of the text in the runs, it successfully set the font size for the scaling I wanted, but the side effect was the rendering issue. In Word if I then reset the font to something for the entire table the rendering problem goes away.
Can you suggest an alternative?
Thanks,
- John

private void StretchTableToFitWindow(Document doc, Table tbl)
{
    // get the width of the page minus the margins
    DocumentBuilder builder = new DocumentBuilder(doc);
    double printWidth = builder.PageSetup.PageWidth - builder.PageSetup.LeftMargin - builder.PageSetup.RightMargin;
    // get the width of the table by adding up the widths of the cells in the first row
    double tableWidth = 0.0;
    foreach (Aspose.Words.Tables.Row r in tbl.Rows)
    {
        double rowWidth = 0;
        foreach (Aspose.Words.Tables.Cell c in r.Cells)
        {
            rowWidth += c.CellFormat.Width;
        }
        if (rowWidth > tableWidth)
            tableWidth = rowWidth;
        r.RowFormat.AllowAutoFit = true;
    }
    if (tableWidth == printWidth)
    {
        // we are good... do nothing
    }
    else
    {
        // calculate the amount to adjust the cell widths
        double scale = printWidth / tableWidth;
        // adjust the cell widths and font sizes accordingly
        foreach (Aspose.Words.Tables.Row r in tbl.Rows)
        {
            foreach (Aspose.Words.Tables.Cell c in r.Cells)
            {
                double newWidth = c.CellFormat.Width * scale;
                c.CellFormat.Width = newWidth;
                foreach (Paragraph p in c.Paragraphs)
                {
                    p.ParagraphFormat.Style.Font.Size = c.FirstParagraph.ParagraphFormat.Style.Font.Size * scale;
                    foreach (Run pr in p.Runs)
                    {
                        pr.Font.Size = pr.Font.Size * scale;
                    }
                }
            }
            // Set height of current row
            r.RowFormat.Height = r.RowFormat.Height * scale;
            r.RowFormat.HeightRule = HeightRule.AtLeast;
        }
    }
}

Hi
Thanks for your inquiry. Please try using the following code instead yours.

private void StretchTableToFitWindow(Document doc, Table tbl)
{
    // get the width of the page minus the margins
    DocumentBuilder builder = new DocumentBuilder(doc);
    double printWidth = builder.PageSetup.PageWidth - builder.PageSetup.LeftMargin - builder.PageSetup.RightMargin;
    // get the width of the table by adding up the widths of the cells in the first row
    double tableWidth = 0.0;
    foreach (Aspose.Words.Tables.Row r in tbl.Rows)
    {
        double rowWidth = 0;
        foreach (Aspose.Words.Tables.Cell c in r.Cells)
        {
            rowWidth += c.CellFormat.Width;
        }
        if (rowWidth > tableWidth)
            tableWidth = rowWidth;
        r.RowFormat.AllowAutoFit = true;
    }
    if (tableWidth == printWidth)
    {
        // we are good... do nothing
    }
    else
    {
        // calculate the amount to adjust the cell widths
        double scale = printWidth / tableWidth;
        // adjust the cell widths and font sizes accordingly
        foreach (Aspose.Words.Tables.Row r in tbl.Rows)
        {
            foreach (Aspose.Words.Tables.Cell c in r.Cells)
            {
                double newWidth = Math.Round(c.CellFormat.Width * scale, 1);
                c.CellFormat.Width = newWidth;
                foreach (Paragraph p in c.Paragraphs)
                {
                    p.ParagraphBreakFont.Size = Math.Round(c.FirstParagraph.ParagraphBreakFont.Size * scale, 1);
                    foreach (Run pr in p.Runs)
                    {
                        pr.Font.Size = Math.Round(pr.Font.Size * scale, 1);
                    }
                }
            }
            // Set height of current row
            r.RowFormat.Height = Math.Round(r.RowFormat.Height * scale, 1);
            r.RowFormat.HeightRule = HeightRule.AtLeast;
        }
    }
}

Hope this helps.
Best regards.