Sign In  Sign Up Live-Chat

Excel2Word

Last post 09-17-2008, 9:16 AM by harris corp. 24 replies.
Page 2 of 2 (25 items)   < Previous 1 2
Sort Posts: Previous Next
  •  09-05-2008, 11:40 AM 142628 in reply to 142620

    Re: Excel2Word

    Hi

     

    Thanks for your inquiry. In the Xls2Doc I used the following formula to calculate width and height of cell

    wordSize = excelSize * 0.75

     

    Try using ConvertUtil to do the same.

    wordSize = ConvertUtil.PixelToPoint(excelSize);

     

    I hope this helps to resolve problem with cell widths.

     

    Regarding “stretch to fit wide options” it is not quite clear for me what you mean. Could you change the word document to show me what the proper output should be?

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  09-05-2008, 11:51 AM 142630 in reply to 142620

    Re: Excel2Word

    Attachment: Present (inaccessible)

    Sorry about that, I should have included it the first time.

    - John

     
  •  09-05-2008, 2:14 PM 142660 in reply to 142630

    Re: Excel2Word

    Hi

     

    Thanks for your inquiry. The differences occur because from Aspose.Cells width and height are returned in Pexels so we need to convert pixels to points. I tried to use ConvertUtil but get the same result. You can try using some coefficient to solve this.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  09-13-2008, 11:39 AM 143937 in reply to 142660

    Re: Excel2Word

    Attachment: Present (inaccessible)

    Hi, I am lcsvb. We just got our official license, so I am using my corporate id instead.

    My 1 remaining issue is a little complicated...

    I need to be able to insert page-breaks into the converted report as well as word documents which serve as sub reports to the main report. Earlier in this thread you showed me how to insert the documents, and I have that part working. But now I need to be able to insert page breaks at known row numbers from the excel spread sheet. I know the row numbers for each of the related page-breaks and sub-reports. The page-breaks and documents can be inserted at any location in the document, like this...

    ---------------- start of document ----------------------

    table part

    --------------- page-break -------------

    table part

    ------------ sub-report word document

    table part

    ----------- page-break --------------

    table part

    ---------- end of document ------------

    Thoughts?

     
  •  09-14-2008, 4:18 AM 143950 in reply to 143937

    Re: Excel2Word

    Hi

     

    Thanks for your inquiry. You should split tables and then insert PageBreak between sub tables. For example see the following code:

     

    //Open document and create documentBuilder

    Document doc = new Document(@"Test084\in.doc");

    DocumentBuilder builder = new DocumentBuilder(doc);

     

    //Get table from document

    Table tab = doc.FirstSection.Body.Tables[0];

     

    //Let's insert page break after 5th row

    //We should create new table

    Table subTable = (Table)tab.Clone(false);

     

    //Also we should create empty paragraph

    //And insert it directly after table

    Paragraph par = new Paragraph(doc);

    tab.ParentNode.InsertAfter(par, tab);

     

    //Now we should insert new table after thsi paragraph

    par.ParentNode.InsertAfter(subTable, par);

     

    //Cut all rows after 5th row and insert them into the sub table

    while (tab.IndexOf(tab.LastRow) != 4)

    {

        subTable.Rows.Insert(0, tab.LastRow);

    }

     

    //And now we can insert Page Break

    //we should move DocumentBuilder cursor to the paragraph

    //between sub tables

    builder.MoveTo(par);

    builder.InsertBreak(BreakType.PageBreak);

     

    //Save document

    doc.Save(@"Test084\out.doc");

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  09-16-2008, 12:02 PM 144266 in reply to 142620

    Re: Excel2Word

    When I add a table to the end of a document, it always inserts a paragraph before the table. Is there any way to suppress it? Here is the code I am using...

            private void AddTable(Worksheet excelWorksheet, Document doc, int sectionfirstrow, int sectionlastrow, int rowStartIndex, int columnStartIndex, int newColumnStartIndex, ArrayList tablePartList)
            {
                //Create a new Word table
                Table wordsTable = new Table(doc);

                //Loop through rows in the Excel worksheet
                for (int rowIndex = sectionfirstrow; rowIndex <= sectionlastrow; rowIndex++)
                {
                    //Create new row
                    Aspose.Words.Tables.Row wordsRow = new Aspose.Words.Tables.Row(doc);

                    //Get collection of Excel cells
                    Aspose.Cells.Cells cells = excelWorksheet.Cells;
                   
                    //Set height of current row
                    wordsRow.RowFormat.Height = cells.GetRowHeightPixel(rowIndex) * 0.71; // 0.75;
                    wordsRow.RowFormat.HeightRule = HeightRule.Exactly;

                    // apply centering to the row as needed
                    if (excelWorksheet.PageSetup.CenterHorizontally)
                        wordsRow.RowFormat.Alignment = RowAlignment.Center;

                    // Append current row to current table.
                    wordsTable.AppendChild(wordsRow);

                    //Loop through columns and add columns to Word table while table's width < maxWidth
                    for (int columnIndex = columnStartIndex; columnIndex < newColumnStartIndex; columnIndex++)
                    {
                        //Convert Excel cell to Word cell (cell width is set in ImportExcelCell)
                        Aspose.Words.Tables.Cell wordsCell = ImportExcelCell(doc, cells, rowIndex, columnIndex);
                   
                        //Insert cell into the row
                        wordsRow.AppendChild(wordsCell);
                    }
                }

                //Add Word table to ArrayList
                tablePartList.Add(wordsTable);
            }

     
  •  09-16-2008, 2:34 PM 144291 in reply to 144266

    Re: Excel2Word

    Hi

     

    Thanks for your inquiry. This code just create list of tables that will be inserted into the document. You can try use InsertBefore method to insert tables before paragraph.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  09-16-2008, 3:33 PM 144299 in reply to 144291

    Re: Excel2Word

    Attachment: Present (inaccessible)

    Sorry about that :(. Here'e the code I am working with. It works except that now it is ignoring my pagebreaks. The pagebreak was supposed to be before the words 'Basis of Estimate'.  See attached doc.

                    // Insert all tables and page-breaks into the Word document
                    // the table_break_items should always be one less or the same as the numbers of tables since that is the criteria for breaking the table into table parts
                    int table_break_item_index = 0;
                    for (int table_index = tablePartsArray.Count - 1; table_index >= 0; table_index--) // these were created in reverse order (in GetTablePart) so we have to roll them out again in reverse order
                    {
                        //Move cursor to document end
                        builder.MoveToDocumentEnd();

                        //Insert table
                        builder.CurrentSection.Body.InsertBefore((Node)tablePartsArray[table_index], builder.CurrentParagraph);
                        //builder.CurrentSection.Body.AppendChild((Node)tablePartsArray[table_index]);

                        //Move cursor to document end
                        builder.MoveToDocumentEnd();

                        // insert the document or page-break
                        if (table_break_items.Count > 0 && table_break_item_index < table_break_items.Count)
                        {
                            table_break tb = (table_break)table_break_items.GetByIndex(table_break_item_index);
                            if (tb.tablebreaktype == table_break_type.document)
                                AppendDoc(doc, GetSubReportDocument(tb.doc));
                            else
                                builder.InsertBreak(BreakType.PageBreak);

                            table_break_item_index++;
                        }
                    }

     
  •  09-17-2008, 4:06 AM 144384 in reply to 144299

    Re: Excel2Word

    Hi

     

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

     

    // Insert all tables and page-breaks into the Word document

    // the table_break_items should always be one less or the same as the numbers of tables since that is the criteria for breaking the table into table parts

    int table_break_item_index = 0;

    for (int table_index = tablePartsArray.Count - 1; table_index >= 0; table_index--) // these were created in reverse order (in GetTablePart) so we have to roll them out again in reverse order

    {

        //Move cursor to document end

        builder.MoveToDocumentEnd();

     

        //Insert table

        builder.CurrentSection.Body.InsertBefore((Node)tablePartsArray[table_index], builder.CurrentParagraph);

     

        //Move cursor to document end

        builder.MoveToDocumentEnd();

     

        // insert the document or page-break

        if (table_break_items.Count > 0 && table_break_item_index < table_break_items.Count)

        {

            table_break tb = (table_break)table_break_items.GetByIndex(table_break_item_index);

            if (tb.tablebreaktype == table_break_type.document)

                AppendDoc(doc, GetSubReportDocument(tb.doc));

            else

                builder.InsertBreak(BreakType.SectionBreakNewPage);

     

            table_break_item_index++;

        }

    }

     

    I highlighted my changes.

     

    I hope this could help you.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  09-17-2008, 9:16 AM 144450 in reply to 144384

    Re: Excel2Word

    Works beautifully. Thank you so much for all of your help!

    - John

     
Page 2 of 2 (25 items)   < Previous 1 2
View as RSS news feed in XML