Exemple #1
0
        public void  WritingInWordDocument()
        {
            using (DocumentFormat.OpenXml.Packaging.WordprocessingDocument wordDocument =
                       WordprocessingDocument.Create(@"C:\\Users\\Public\\Music\\info.doc", WordprocessingDocumentType.Document))
            {
                MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();

                // Create the document structure and add some text.
                mainPart.Document = new Document();
                Body      body = mainPart.Document.AppendChild(new Body());
                Paragraph para = body.AppendChild(new Paragraph());
                Run       run  = para.AppendChild(new Run());
                run.AppendChild(new Text("Hello, my name is Sumit."));
            }
        }
Exemple #2
0
    private void generatedocxfile(StringBuilder strHTMLContent, string FederationName)
    {
        /*t create and init a new docx file and
         * a WordprocessingDocument object to represent it t*/

        string docPath = getPPRPath();

        //string docPath=GetSavePath();

        DocumentFormat.OpenXml.Packaging.WordprocessingDocument doc = DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Create(docPath + FederationName + ".docx", WordprocessingDocumentType.Document);
        MainDocumentPart mainDocPart = doc.AddMainDocumentPart();

        mainDocPart.Document = new Document();
        Body body = new Body();

        mainDocPart.Document.Append(body);

        // Add an aFChunk part to the package
        string altChunkId = "AltChunkId1";

        AlternativeFormatImportPart chunk = mainDocPart
                                            .AddAlternativeFormatImportPart(
            AlternativeFormatImportPartType.Xhtml, altChunkId);

        string html = strHTMLContent.ToString();

        using (MemoryStream ms =
                   new MemoryStream(Encoding.UTF8.GetBytes(html)))
        {
            chunk.FeedData(ms);
        }

        // Add the aFChunk to the document
        AltChunk altChunk = new AltChunk();

        altChunk.Id = altChunkId;
        mainDocPart.Document.Body.Append(altChunk);

        /*t to save the changes t*/
        doc.MainDocumentPart.Document.Save();
        doc.Dispose();
    }