Sign In  Sign Up Live-Chat

Excel2Word

Last post 09-17-2008, 9:16 AM by harris corp. 24 replies.
Page 1 of 2 (25 items)   1 2 Next >
Sort Posts: Previous Next
  •  08-26-2008, 4:32 PM 141325

    Excel2Word

    I need to be able to insert a document into another document (bounded by section breaks to preserve formatting). How should I do this? I tried to modify ConvertPictureToShape (from the Excel2Word sample application) but that doesn't seem to work and I don't think it will give me the result I am looking for.

     

    Any Suggestions?

    Filed under: ole Object
     
  •  08-26-2008, 5:01 PM 141326 in reply to 141325

    Re: Excel2Word

    Hello!

     

    Thank you for your interest in Aspose.Words.

     

    That’s not clear what you are trying to achieve. If you’d like to append one MS Word document to another or concatenate several documents please refer to this documentation article:

    http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/append-one-document-to-another.html

     

    Let me know if this helps and feel free to ask any other questions.

     

    Regards,
    Viktor Sazhaev
    Software Engineer, Aspose Auckland Team
     
  •  08-27-2008, 7:41 AM 141421 in reply to 141326

    Re: Excel2Word

    I am sorry for the confusion.

     

    Here’s our process…

     

    Our current processing using .Net to write Word reports using Microsoft VSTO…

     

    We create a report in Excel with tabular data only including formatting (bold, merge, borders, etc). There are no pictures or OLE Objects in the Excel.

     

    I have also written an Excel to Word converter using VSTO that converts the Excel file to Word. While converting the report from Excel to Word, I search the document for the “markers” that indicate the filename of a Word document I am supposed to insert at that location in the report. If I find one of these, I insert a section-break at that location, the contents of the Word document and another section break. Then I continue looking for more markers of other documents that are to be inserted.

     

    Here’s a pseudo-code that shows what I want to accomplish…

      

    Open Excel file with report contents already created

    "Copy" Report contents from Excel

    Create new "main" Word doc

    "Paste" Report contents into "main" Word doc

    Search for First “Word doc Marker” in "main"

    While “Word doc Marker” is found

    {

                    Remove “Word doc Marker”

                    Insert Section Break into "main" Word doc

                    Read Word File "Word doc Marker" into "inserted Word doc

                    Insert "inserted" Word doc into "main" Word doc

                    Insert Section Break

                    Search for Next “Word doc Marker”

    }

    Save "main" Word File

     

    Thank You for Your help.

     
  •  08-27-2008, 8:09 AM 141430 in reply to 141421

    Re: Excel2Word

    Hi

     

    Thanks for your inquiry. I think that you can use bookmark as marker and use InsertDocument method. Please see the following link for more information:

    http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/insert-a-document-into-another-document.html

     

    Also if marker is just plain text you can use ReplaceEvaluator. See the following link for more information.

    http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/find-and-replace.html

     

    Also there is a demo for Excel2Word conversion. See the following link:

    http://www.aspose.com/community/files/51/file-format-components/aspose.words/entry112559.aspx

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  08-27-2008, 8:46 AM 141440 in reply to 141430

    Re: Excel2Word

    Attachment: Present (inaccessible)

    Excellent!

    One more question. How do I search for a marker which has a 'name' attached to it so I can use the name to go to my database and get the document contents. Please see the red text in the attached excel spreadsheet as an example...

     

     
  •  08-27-2008, 8:51 AM 141441 in reply to 141440

    Re: Excel2Word

    Attachment: Present (inaccessible)
    Oops, attached wiorng file. Try this one.
     
  •  08-27-2008, 11:21 AM 141479 in reply to 141441

    Re: Excel2Word

    Hi

     

    Thank you for additional information. Here is sample code:

     

    public void Test056()

    {

        //Open document

        //The document is output document of Xls2Doc convertor

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

        Regex regex = new Regex("WBSDESC");

        doc.Range.Replace(regex, new ReplaceEvaluator(Replace056), false);

     

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

    }

    private ReplaceAction Replace056(object sender, ReplaceEvaluatorArgs e)

    {

        //Get match Run

        Run run = (Run)e.MatchNode;

        //Matched node is child of Table Row

        Row row = (Row)run.GetAncestor(NodeType.Row);

        //We should split table and insert document between sub tables

        //Create new table

        Table newTable = new Table(e.MatchNode.Document);

        //Copy rows after matched row to the new table

        while (row.NextSibling != null)

        {

            newTable.AppendChild(row.NextSibling);

        }

        //We should insert the newly created table after original table

        //But first we should insert empty paragraph

        Paragraph par = new Paragraph(e.MatchNode.Document);

        row.ParentTable.ParentNode.InsertAfter(par, row.ParentTable);

        //And insert table

        par.ParentNode.InsertAfter(newTable, par);

        //Now we can insert insert document

        //Open corresponding document

        //I assume that you will use information from

        //run.Text to get document from DB. Here I just open document

        Document doc = new Document(@"Test056\test.doc");

        InsertDocument(par, doc);

        //Also we should remove matched row

        row.Remove();

        return ReplaceAction.Skip;

    }

     

    I hope this could help you.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  09-04-2008, 8:31 AM 142378 in reply to 141479

    Re: Excel2Word

    Attachment: Present (inaccessible)

    Thank you for your help. I am getting closer.

    I have attached 3 files to help describe my situation.

    The file report.xls is the base report. I run the Excel2Word converter with my Modifications to insert the file WBSDESC.doc after row 6 of the spreadsheet. The output file is report.doc.

    As you can see I am getting the document inserted.

    The problem I am having is that the margins on the latter half of the report changed because of the inserted docuement. How do I isolate the inserted document, so it's formatting and margins and so forth do not mess up the rest of the target document? I tried using section breaks to fix this, but it is not working.

    Here's the code I am using to insert the sub-report document...

            private void AppendDoc(Document dstDoc, Document srcDoc)
            {
                // insert a section break before the appended docs to preserve formatting
                DocumentBuilder builder = new DocumentBuilder(dstDoc);
                builder.MoveToDocumentEnd();
                builder.InsertBreak(BreakType.SectionBreakContinuous);

                srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;
                // Loop through all sections in the source document.
                // Section nodes are immediate children of the Document node so we can just enumerate the Document.
                foreach (Section srcSection in srcDoc)
                {
                    // Because we are copying a section from one document to another,
                    // it is required to import the Section node into the destination document.
                    // This adjusts any document-specific references to styles, lists, etc.
                    //
                    // Importing a node creates a copy of the original node, but the copy
                    // is ready to be inserted into the destination document.
                    Node dstSection = dstDoc.ImportNode(srcSection, true, ImportFormatMode.KeepSourceFormatting);

                    // Now the new section node can be appended to the destination document.
                    dstDoc.AppendChild(dstSection);
                }

                // insert a section break after the appended docs to preserve formatting
                builder.MoveToDocumentEnd();
                builder.InsertBreak(BreakType.SectionBreakContinuous);
            }

     

    Thanks in advance for your help.

    - John

     
  •  09-04-2008, 9:32 AM 142384 in reply to 142378

    Re: Excel2Word

    Hi

     

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

     

    private void AppendDoc(Document dstDoc, Document srcDoc)

    {

        // insert a section break before the appended docs to preserve formatting

        DocumentBuilder builder = new DocumentBuilder(dstDoc);

        builder.MoveToDocumentEnd();

        builder.InsertBreak(BreakType.SectionBreakContinuous);

        Section currentSect = builder.CurrentSection;

        srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;

        // Loop through all sections in the source document.

        // Section nodes are immediate children of the Document node so we can just enumerate the Document.

        foreach (Section srcSection in srcDoc)

        {

            // Because we are copying a section from one document to another,

            // it is required to import the Section node into the destination document.

            // This adjusts any document-specific references to styles, lists, etc.

            //

            // Importing a node creates a copy of the original node, but the copy

            // is ready to be inserted into the destination document.

            Node dstSection = dstDoc.ImportNode(srcSection, true, ImportFormatMode.KeepSourceFormatting);

     

            // Now the new section node can be appended to the destination document.

            dstDoc.InsertBefore(dstSection, currentSect);

        }

    }

     

    I highlighted my changes.

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  09-04-2008, 10:01 AM 142387 in reply to 142384

    Re: Excel2Word

    Attachment: Present (inaccessible)

    Sweet!!! That worked perfectly.

    One more question. Before each table is a paragraph marker. Is there any way to suppress it?

    See attached doc. (May need to turn on All Formatting Marks in Tools Options?

     
  •  09-04-2008, 10:03 AM 142388 in reply to 142387

    Re: Excel2Word

    Another question related to this. After I insert the sub-report documetn, I need to know if there is enough space left on the last page to fit more of the main report. How do I determine the amount of space left (in inches maybe) on the last page after I have instered a doc. If there is not st least 1 inch of space, I was thinking I would insert a hard page-break.

    Please advise.

    - John

     
  •  09-04-2008, 10:36 AM 142392 in reply to 142388

    Re: Excel2Word

    Hi

     

    Thanks you for your request.

     

    1. There is no way to turn of these options using Aspose.Words because these options are not stored in the document.

     

    2. Unfortunately there is no way to determine the amount of space left on the page. Aspose.Words document represents content and formatting of a document, not its layout into lines and pages. This feature is called pagination and it is not released yet. Please see FAQ for more information.

     

    Best regards,


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  09-04-2008, 12:42 PM 142424 in reply to 142392

    Re: Excel2Word

    Hello,

    Now I am trying to convert some VSTO code to Aspose.cells:

    I used to do this in VSTO...

                Excel.Worksheet wks = ...; // get excel worksheet
                object oRange = (object)("A1:C3");
                wks.get_Range(oRange, Type.Missing).NumberFormat = "#,##0";

    How do I do that in Aspose.Cells?

    Thanks,

    - John

     
  •  09-04-2008, 1:40 PM 142452 in reply to 142424

    Re: Excel2Word

    Hi

     

    Thanks for your inquiry. I think you should ask this question in Aspose.Cells forum.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  09-05-2008, 10:37 AM 142620 in reply to 141325

    Re: Excel2Word

    Attachment: Present (inaccessible)

    Ok,

    Thanks to your help, I am 95% there. I have a couple of last little things that need to be resolved and I could use your suggestions.

    Please take a look at the xls and doc files attached to this post. The doc was created by the converterXls2Doc class. Notice how the doc file has not preserved the stretch to fit wide options that are in place in the xls file. Also, I need all the columns in the word doc to have the same widths as they are in the Excel file.

    Can you suggest how to fix this?

    Thanks again.

    - John

     
Page 1 of 2 (25 items)   1 2 Next >