Converting XLS to Doc

Hi,
I want to covert the attached xls to word using aspose cells, it is getting converted but format is lost like not converting within the margin & max column is coming as 6 instead of 7 because of which one column data is getting cut. Kindly suggest what is wrong with the xls.

Thanks in Advance,
Gopal

Hi
Thanks for your request. I tried converting your XLS file to DOC on my side and as I can see the output document looks as expected. If you open your workbook and switch to print preview, you will see mostly the same result as you see in the DOC generated by the converter.
Best regards,

can you share your program used for conversion. I will try it out here.

Hi
Thanks for your request. Sure, here is my converter.
Best regards,

Hi,
I tried with your program also, my last column is getting cut. I have attached the xls & word document for your reference. Kindly suggest what is the problem.

regards,
Gopal

Hi
Thank you for additional information. Please try to modify the code like shown below:

///
/// This method returns array of Word tables, every table in this array represents a part of Excel worksheet.
///
/// Input worksheet
/// Parent document
/// Array of Word tables
private ArrayList GetTablePartsArray(Worksheet excelWorksheet, Document doc) throws Exception
{
    // Get column index of cell that contains data
    int colCount = excelWorksheet.getCells().getMaxColumn() + 1;
    // Get row index of cell that contains data
    int rowCount = excelWorksheet.getCells().getMaxRow() + 1;
    int startColumn = excelWorksheet.getCells().getMinColumn();
    int startRow = excelWorksheet.getCells().getMinRow();
    // Get area in the worksheet that will be printed
    // Returns something like this "A1:D51" of null
    String excelPrintArea = excelWorksheet.getPageSetup().getPrintArea();
    if (!excelPrintArea.equals(""))
    {
        // Get first cell in the printed area
        String rangeStart = excelPrintArea.substring(0, excelPrintArea.indexOf(":"));
        // Get last cell in the printed area
        String rangeEnd = excelPrintArea.substring(excelPrintArea.indexOf(":") + 1);
        // Get printed range from worksheet
        com.aspose.cells.NamedRange range = excelWorksheet.getCells().createNamedRange("Print Range", rangeStart, rangeEnd);
        colCount = range.getEndColumn() + 1;
        rowCount = range.getEndRow() + 1;
        startColumn = range.getStartColumn();
        startRow = range.getStartRow();
    }
    // Extract objects like Pictures, Charts, etc and store in the HashTable // if worksheet contains object that is placed outside the region then resize region (count of rows and columns)
    com.aspose.cells.NamedRange drawRange = ExtractDrawingObjects(excelWorksheet);
    if ((drawRange.getEndRow() - drawRange.getStartRow())> rowCount)
        rowCount = drawRange.getEndRow() - drawRange.getStartRow();
    if ((drawRange.getEndColumn() - drawRange.getStartColumn())> colCount)
        colCount = drawRange.getEndColumn() - drawRange.getStartColumn();
    if (drawRange.getStartRow() <startRow)
        startRow = drawRange.getStartRow();
    if (drawRange.getStartColumn() <startColumn)
        startColumn = drawRange.getStartColumn();
    if (startRow <0)
        startRow = 0;
    if (startColumn <0)
        startColumn = 0;
    // Create ampty ArrayList
    ArrayList tablePartList = new ArrayList();
    // split worksheet into a tables collection
    GetTablePart(excelWorksheet, doc, tablePartList, startColumn, startRow, colCount, rowCount);
    return tablePartList;
}

Hope this helps.
Best regards,

Thanks, It works with the above code change.
I have one clarification, will this work for all kind of xls files.

Regards,
Gopal

Hi
Thanks for your request. Yes, this should work for all documents. The problem occurs because the index of the last column was used as a number of columns, but index is zero based, so we have to add one.
Best regards,