コード例 #1
0
ファイル: FieldsTest.cs プロジェクト: zhaoyin/officeOBA
        public void SimpleDateFieldTest()
        {
            // Create a new text document
            TextDocument td = new TextDocument();

            td.New();
            // Create a new paragraph
            Paragraph p  = new Paragraph(td);
            DateField df = new DateField(td);

            // Set fixed to false whch means that the current date is displayed
            df.Fixed = false;
            // add the date field to content
            p.Content.Add(df);
            td.Content.Add(p);

            // test import/export
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                td.Save(AARunMeFirstAndOnce.outPutFolder + "field_date.odt", new OpenDocumentTextExporter(writer));
            }
            //td.Load(AARunMeFirstAndOnce.outPutFolder + "field_date.odt");
            //td.Fields.RemoveAt(0);
            // this document should be empty now!!!
            //td.Save(AARunMeFirstAndOnce.outPutFolder + "field_date2.odt");
        }
コード例 #2
0
ファイル: FieldsTest.cs プロジェクト: zhaoyin/officeOBA
        public void VariableSetTest()
        {
            // Create a new text document
            TextDocument td = new TextDocument();

            td.New();

            // Create a variable declaration
            VariableDecl vd = new VariableDecl(td, VariableValueType.String, "test");

            td.VariableDeclarations.Add(vd);
            // add a variable-set field
            Paragraph p1 = new Paragraph(td);

            p1.Content.Add(new VariableSet(td, vd, "test variable-set"));
            td.Content.Add(p1);

            // saveload test
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                td.Save(AARunMeFirstAndOnce.outPutFolder + "varset.odt", new OpenDocumentTextExporter(writer));
            }
            using (IPackageReader reader = new OnDiskPackageReader())
            {
                td.Load(AARunMeFirstAndOnce.outPutFolder + "varset.odt", new OpenDocumentImporter(reader));
                using (IPackageWriter writer = new OnDiskPackageWriter())
                {
                    td.Save(AARunMeFirstAndOnce.outPutFolder + "varset2.odt", new OpenDocumentTextExporter(writer));
                }
            }
        }
コード例 #3
0
        public void ManipulateACommonStyle()
        {
            TextDocument document = new TextDocument();

            document.New();
            Assert.IsTrue(document.CommonStyles.Count > 0, "Common style resp. style templates must be loaded");
            //Find a Header template
            IStyle style = document.CommonStyles.GetStyleByName("Heading_20_1");

            Assert.IsNotNull(style, "Style with name Heading_20_1 must exist");
            Assert.IsTrue(style is ParagraphStyle, "style must be a ParagraphStyle");
            ((ParagraphStyle)style).TextProperties.FontName = FontFamilies.BroadwayBT;
            //Create a header that use the standard style Heading_20_1
            Header header = new Header(document, Headings.Heading_20_1);

            //Add some text
            header.TextContent.Add(new SimpleText(document, "I am the header text and my style template is modified :)"));
            //Add header to the document
            document.Content.Add(header);
            //save the document
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                document.Save(AARunMeFirstAndOnce.outPutFolder + "modifiedCommonStyle.odt", new OpenDocumentTextExporter(writer));
            }
        }
コード例 #4
0
ファイル: FrameTest.cs プロジェクト: zhaoyin/officeOBA
        public void DrawTextBox()
        {
            //New TextDocument
            TextDocument textdocument = new TextDocument();

            textdocument.New();
            //Standard Paragraph
            Paragraph paragraphOuter = new Paragraph(textdocument, ParentStyles.Standard.ToString());
            //Create Frame for DrawTextBox
            Frame frameOuter = new Frame(textdocument, "frame1");
            //Create DrawTextBox
            DrawTextBox drawTextBox = new DrawTextBox(textdocument);
            //Create a paragraph for the drawing frame
            Paragraph paragraphInner = new Paragraph(textdocument, ParentStyles.Standard.ToString());
            //Create the frame with the Illustration resp. Graphic
            Frame frameIllustration = new Frame(textdocument, "frame2", "graphic1", new DiskFile(_imagefile));

            //Add Illustration frame to the inner Paragraph
            paragraphInner.Content.Add(frameIllustration);
            //Add inner Paragraph to the DrawTextBox
            drawTextBox.Content.Add(paragraphInner);
            //Add the DrawTextBox to the outer Frame
            frameOuter.Content.Add(drawTextBox);
            //Add the outer Frame to the outer Paragraph
            paragraphOuter.Content.Add(frameOuter);
            //Add the outer Paragraph to the TextDocument
            textdocument.Content.Add(paragraphOuter);
            //Save the document
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                textdocument.Save(_framefile2, new OpenDocumentTextExporter(writer));
            }
        }
コード例 #5
0
        public void TestCloning()
        {
            TextDocument document = new TextDocument();

            document.New();
            Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);

            paragraph.TextContent.Add(new SimpleText(document, "Some text"));
            Paragraph paragraphClone = (Paragraph)paragraph.Clone();
            //Assert.AreEqual(paragraph.Node, paragraphClone.Node, "Should be cloned and not equal.");
            //Assert.AreEqual(paragraph.TextContent[0].GetType(), paragraphClone.TextContent[0].GetType(), "Should be cloned and equal.");
            ParagraphStyle paragraphStyle = new ParagraphStyle(document, "P1");

            paragraphStyle.TextProperties.Bold = "bold";
            //Add paragraph style to the document,
            //only automaticaly created styles will be added also automaticaly
            document.Styles.Add(paragraphStyle);
            paragraphClone.ParagraphStyle = paragraphStyle;
            //Clone the clone
            Paragraph paragraphClone2 = (Paragraph)paragraphClone.Clone();

            Assert.AreNotEqual(paragraphClone2.Node, paragraphClone.Node, "Should be cloned and not equal.");
            Assert.AreEqual(paragraphClone2.TextContent[0].GetType(), paragraphClone.TextContent[0].GetType(), "Should be cloned and equal.");
            //Cloning of styles isn't supported!
            Assert.AreSame(paragraphClone2.ParagraphStyle, paragraphClone.ParagraphStyle, "Must be same style object. Styles have to be cloned explicitly.");
            document.Content.Add(paragraph);
            document.Content.Add(paragraphClone);
            document.Content.Add(paragraphClone2);
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                document.Save(AARunMeFirstAndOnce.outPutFolder + "clonedParagraphs.odt", new OpenDocumentTextExporter(writer));
            }
        }
コード例 #6
0
ファイル: FieldsTest.cs プロジェクト: zhaoyin/officeOBA
        public void PageNumberTest()
        {
            TextDocument td = new TextDocument();

            td.New();

            Paragraph p1 = new Paragraph(td);

            p1.TextContent.Add(new SimpleText(td, "This is a current page number: "));
            PageNumber pn = new PageNumber(td);

            p1.Content.Add(pn);
            td.Content.Add(p1);

            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                td.Save(AARunMeFirstAndOnce.outPutFolder + "page_number.odt", new OpenDocumentTextExporter(writer));
            }
            using (IPackageReader reader = new OnDiskPackageReader())
            {
                td.Load(AARunMeFirstAndOnce.outPutFolder + "page_number.odt", new OpenDocumentImporter(reader));
                using (IPackageWriter writer = new OnDiskPackageWriter())
                {
                    td.Save(AARunMeFirstAndOnce.outPutFolder + "page_number2.odt", new OpenDocumentTextExporter(writer));
                }
            }
        }
コード例 #7
0
 /// <summary>
 /// Creates the bill.
 /// </summary>
 public string CreateBill()
 {
     try
     {
         string billingTemplate = Path.Combine(Application.StartupPath, @"Resources\bill_template.odt");
         if (File.Exists(billingTemplate))
         {
             string       billFile   = Path.Combine(Application.StartupPath, "bill.odt");
             TextDocument billingDoc = new TextDocument();
             using (IPackageReader reader = new OnDiskPackageReader())
             {
                 billingDoc.Load(billingTemplate, new OpenDocumentImporter(reader));
             }
             this.WriteBillingItems(billingDoc);
             this.WriteCustomerAndDate(billingDoc);
             using (IPackageWriter writer = new OnDiskPackageWriter())
             {
                 billingDoc.Save(billFile, new OpenDocumentTextExporter(writer));
             }
             return(billFile);
         }
         else
         {
             throw new Exception("The billing template wasn't found!\n" + billingTemplate);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #8
0
        public void SimpleTable()
        {
            //Create a new text document
            TextDocument document = new TextDocument();

            document.New();
            //Create a table for a text document using the TableBuilder
            Table table = TableBuilder.CreateTextDocumentTable(
                document,
                "table1",
                "table1",
                3,
                3,
                16.99,
                false,
                false);
            //Create a standard paragraph
            Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);

            //Add some simple text
            paragraph.TextContent.Add(new SimpleText(document, "Some cell text"));
            //Insert paragraph into the first cell
            table.Rows[0].Cells[0].Content.Add(paragraph);
            //Add table to the document
            document.Content.Add(table);
            //Save the document
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                document.Save(AARunMeFirstAndOnce.outPutFolder + "simpleTable.odt", new OpenDocumentTextExporter(writer));
            }
        }
コード例 #9
0
ファイル: GraphicTest.cs プロジェクト: zhaoyin/officeOBA
        public void CreateIllustrationUsingTheFrameBuilder()
        {
            TextDocument document = new TextDocument();

            document.New();
            //Create a standard pargraph for the illustration
            Paragraph paragraphStandard = ParagraphBuilder.CreateStandardTextParagraph(document);
            //Create Illustration Frame using the FrameBuilder
            Frame frameIllustration = FrameBuilder.BuildIllustrationFrame(
                document,
                "illustration_frame_1",
                "graphic1",
                new DiskFile(_imagefile),
                "This is a Illustration",
                1);

            //Add the Illustration Frame to the Paragraph
            paragraphStandard.Content.Add(frameIllustration);
            Assert.IsTrue(frameIllustration.Content[0] is DrawTextBox, "Must be a DrawTextBox!");
            Assert.IsTrue(((DrawTextBox)frameIllustration.Content[0]).Content[0] is Paragraph, "Must be a Paragraph!");
            Paragraph paragraph = ((DrawTextBox)frameIllustration.Content[0]).Content[0] as Paragraph;

            Assert.IsTrue(paragraph.TextContent[1] is TextSequence, "Must be a TextSequence!");
            //Add Paragraph to the document
            document.Content.Add(paragraphStandard);
            //Save the document
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                document.Save(AARunMeFirstAndOnce.outPutFolder + "illustration.odt", new OpenDocumentTextExporter(writer));
            }
        }
コード例 #10
0
ファイル: FieldsTest.cs プロジェクト: zhaoyin/officeOBA
        public void VariableDeclTest()
        {
            // Create a new text document
            TextDocument td = new TextDocument();

            td.New();

            // Declare two variables
            VariableDecl vd  = new VariableDecl(td, VariableValueType.String, "test");
            VariableDecl vd2 = new VariableDecl(td, VariableValueType.Float, "12.3");

            td.VariableDeclarations.Add(vd);
            td.VariableDeclarations.Add(vd2);

            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                td.Save(AARunMeFirstAndOnce.outPutFolder + "vardecls.odt", new OpenDocumentTextExporter(writer));
            }

            TextDocument td2 = new TextDocument();

            // Reload the document and make some changes
            using (IPackageReader reader = new OnDiskPackageReader())
            {
                td2.Load(AARunMeFirstAndOnce.outPutFolder + "vardecls.odt", new OpenDocumentImporter(reader));
                td2.VariableDeclarations[0].Name = "xyz";
                td2.VariableDeclarations.Add(new VariableDecl(td, VariableValueType.String, "test222"));

                // Unzip the document and check its content.xml file!
                using (IPackageWriter writer = new OnDiskPackageWriter())
                {
                    td2.Save(AARunMeFirstAndOnce.outPutFolder + "vardecls2.odt", new OpenDocumentTextExporter(writer));
                }
            }
        }
コード例 #11
0
ファイル: GraphicTest.cs プロジェクト: zhaoyin/officeOBA
        public void LoadGraphicAccessGraphic()
        {
            TextDocument document = new TextDocument();

            using (IPackageReader reader = new OnDiskPackageReader())
            {
                document.Load(AARunMeFirstAndOnce.inPutFolder + "hallo.odt", new OpenDocumentImporter(reader));

                foreach (IContent iContent in document.Content)
                {
                    if (iContent is Paragraph && ((Paragraph)iContent).Content.Count > 0 &&
                        ((Paragraph)iContent).Content[0] is Frame)
                    {
                        Frame frame = ((Paragraph)iContent).Content[0] as Frame;
                        Assert.IsTrue(frame.Content[0] is Graphic, "Must be a graphic!");
                        Graphic graphic = frame.Content[0] as Graphic;
                        //now access the full qualified graphic path
                        Assert.IsNotNull(graphic.GraphicFile, "The graphic real path must exist!");
                        //Assert.IsTrue(File.Exists(graphic.GraphicRealPath));
                    }
                }
                using (IPackageWriter writer = new OnDiskPackageWriter())
                {
                    document.Save(AARunMeFirstAndOnce.outPutFolder + "hallo_rel_graphic_touch.odt", new OpenDocumentTextExporter(writer));
                }
            }
        }
コード例 #12
0
        public void IParagraphCollectionBuilderTest()
        {
            //some text e.g read from a TextBox
            string someText = "Max Mustermann\nMustermann Str. 300\n22222 Hamburg\n\n\n\n"
                              + "Heinz Willi\nDorfstr. 1\n22225 Hamburg\n\n\n\n"
                              + "Offer for 200 Intel Pentium 4 CPU's\n\n\n\n"
                              + "Dear Mr. Willi,\n\n\n\n"
                              + "thank you for your request. \tWe can     offer you the 200 Intel Pentium IV 3 Ghz CPU's for a price of 79,80 € per unit."
                              + "This special offer is valid to 31.10.2005. If you accept, we can deliver within 24 hours.\n\n\n\n"
                              + "Best regards \nMax Mustermann";

            //Create new TextDocument
            TextDocument document = new TextDocument();

            document.New();
            //Use the ParagraphBuilder to split the string into ParagraphCollection
            ParagraphCollection pCollection = ParagraphBuilder.CreateParagraphCollection(
                document,
                someText,
                true,
                ParagraphBuilder.ParagraphSeperator);

            //Add the paragraph collection
            foreach (Paragraph paragraph in pCollection)
            {
                document.Content.Add(paragraph);
            }
            //save
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                document.Save(AARunMeFirstAndOnce.outPutFolder + "Letter.odt", new OpenDocumentTextExporter(writer));
            }
        }
コード例 #13
0
        public void TextDocumentWithImgMapReload()
        {
            string   file  = AARunMeFirstAndOnce.inPutFolder + @"imgmap.odt";
            FileInfo fInfo = new FileInfo(file);
            //Load the text document
            TextDocument document = new TextDocument();

            using (IPackageReader reader = new OnDiskPackageReader())
            {
                document.Load(file, new OpenDocumentImporter(reader));

                IContent iContent = document.Content[2];
                Assert.IsNotNull(iContent, "Must exist!");
                Assert.IsTrue(iContent is Paragraph,
                              "iContent have to be a paragraph! But is :" + iContent.GetType().Name);
                Assert.IsTrue(((Paragraph)iContent).Content[0] is Frame,
                              "Must be a frame! But is :" + ((Paragraph)iContent).Content[0].GetType().Name);
                Frame frame = ((Paragraph)iContent).Content[0] as Frame;
                Assert.IsTrue(frame.Content[1] is ImageMap,
                              "Must be a ImageMap! But is :" + frame.Content[1].GetType().Name);
                ImageMap imageMap = frame.Content[1] as ImageMap;
                Assert.IsTrue(imageMap.Content[0] is DrawAreaRectangle, "Must be a DrawAreaRectangle! But is :"
                              + imageMap.Content[0].GetType().Name);
                //Save it back again
                using (IPackageWriter writer = new OnDiskPackageWriter())
                {
                    document.Save(AARunMeFirstAndOnce.outPutFolder + fInfo.Name + ".rel.odt",
                                  new OpenDocumentTextExporter(writer));
                }
            }
        }
コード例 #14
0
        public void ListItemTest()
        {
            //Create a new text document
            TextDocument document = new TextDocument();

            document.New();
            //Create a numbered list
            List li = new List(document, "L1", ListStyles.Bullet, "L1P1");
            //Create a new list item
            ListItem lit = new ListItem(li);

            Assert.IsNotNull(lit.Content, "Content object must exist!");
            //Create a paragraph
            Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);

            //Add some text
            paragraph.TextContent.Add(new SimpleText(document, "First item"));
            //Add paragraph to the list item
            lit.Content.Add(paragraph);
            //Add the list item
            li.Content.Add(lit);
            //Add the list
            document.Content.Add(li);
            //Save document
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                document.Save(AARunMeFirstAndOnce.outPutFolder + "list.odt", new OpenDocumentTextExporter(writer));
            }
        }
コード例 #15
0
ファイル: GraphicTest.cs プロジェクト: zhaoyin/officeOBA
        public void DrawTextBoxTest()
        {
            TextDocument textdocument = new TextDocument();

            textdocument.New();
            Paragraph   pOuter       = ParagraphBuilder.CreateStandardTextParagraph(textdocument);
            DrawTextBox drawTextBox  = new DrawTextBox(textdocument);
            Frame       frameTextBox = new Frame(textdocument, "fr_txt_box");

            frameTextBox.DrawName = "fr_txt_box";
            frameTextBox.ZIndex   = "0";
            //			Paragraph pTextBox				= ParagraphBuilder.CreateStandardTextParagraph(textdocument);
            //			pTextBox.StyleName				= "Illustration";
            Paragraph p = ParagraphBuilder.CreateStandardTextParagraph(textdocument);

            p.StyleName = "Illustration";
            Frame frame = new Frame(textdocument, "frame1",
                                    "graphic1", new DiskFile(_imagefile));

            frame.ZIndex = "1";
            p.Content.Add(frame);
            p.TextContent.Add(new SimpleText(textdocument, "Illustration"));
            drawTextBox.Content.Add(p);

            frameTextBox.SvgWidth = frame.SvgWidth;
            drawTextBox.MinWidth  = frame.SvgWidth;
            drawTextBox.MinHeight = frame.SvgHeight;
            frameTextBox.Content.Add(drawTextBox);
            pOuter.Content.Add(frameTextBox);
            textdocument.Content.Add(pOuter);
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                textdocument.Save(AARunMeFirstAndOnce.outPutFolder + "drawTextbox.odt", new OpenDocumentTextExporter(writer));
            }
        }
コード例 #16
0
        public void NestedTable()
        {
            //Create a new text document
            TextDocument document = new TextDocument();

            document.New();
            //Create a table for a text document using the TableBuilder
            Table table = TableBuilder.CreateTextDocumentTable(
                document,
                "table1",
                "table1",
                3,
                3,
                16.99,
                false,
                false);
            //Create a standard paragraph
            Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);

            //Add some simple text
            paragraph.TextContent.Add(new SimpleText(document, "Some cell text"));
            Assert.IsNotNull(table.Rows, "Must exist.");
            Assert.IsTrue(table.Rows.Count == 3, "There must be 3 rows.");
            //Insert paragraph into the second cell
            table.Rows[0].Cells[1].Content.Add(paragraph);
            //Get width of the nested table
            double nestedTableWidth = SizeConverter.GetDoubleFromAnOfficeSizeValue(
                table.ColumnCollection[0].ColumnStyle.ColumnProperties.Width);
            //Create another table using the TableBuilder
            Table nestedTable = TableBuilder.CreateTextDocumentTable(
                document,
                "table1",
                "table1",
                2,
                2,
                nestedTableWidth,
                false,
                false);

            //Create a new standard paragraph
            paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
            //Add some simple text
            paragraph.TextContent.Add(new SimpleText(document, "Some cell text inside the nested table"));
            Assert.IsNotNull(nestedTable.Rows, "Must exist.");
            Assert.IsTrue(nestedTable.Rows.Count == 2, "There must be 3 rows.");
            //Insert paragraph into the first cell
            nestedTable.Rows[0].Cells[0].Content.Add(paragraph);
            //Insert the nested table into the first row and first cell
            table.Rows[0].Cells[0].Content.Add(nestedTable);
            Assert.IsTrue(table.Rows[0].Cells[0].Content[0] is Table, "Must be the nested table.");
            //Add table to the document
            document.Content.Add(table);
            //Save the document
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                document.Save(AARunMeFirstAndOnce.outPutFolder + "nestedTable.odt", new OpenDocumentTextExporter(writer));
            }
        }
コード例 #17
0
        public void TableOfContentsTest()
        {
            //Create new Document
            TextDocument textDocument = new TextDocument();

            textDocument.New();
            //Create a new Table of contents
            TableOfContents tableOfContents = new TableOfContents(
                textDocument, "Table_Of_Contents", false, false, "Table of Contents");

            //Add the toc
            textDocument.Content.Add(tableOfContents);
            //Create a new heading, there's no need of the chapter number
            string sHeading = "A first headline";
            //The corresponding text entry, here you need to set the
            //chapter number
            string sTocEntry = "1. A first headline";
            Header header    = new Header(
                textDocument, Headings.Heading_20_1);

            header.OutLineLevel = "1";
            header.TextContent.Add(new SimpleText(textDocument, sHeading));
            //add the header to the content
            textDocument.Content.Add(header);
            //add the toc entry text as entry to the Table of contents
            tableOfContents.InsertEntry(sTocEntry, 1);
            //Add some text to this chapter
            Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(textDocument);

            paragraph.TextContent.Add(new SimpleText(textDocument, "I'm the text for the first chapter!"));
            textDocument.Content.Add(paragraph);
            //Add a sub header to the first chapter
            //Create a new heading, there's no need of the chapter number
            sHeading = "A first sub headline";
            //The corresponding text entry, here you need to set the
            //chapter number
            sTocEntry = "1.1. A first sub headline";
            header    = new Header(
                textDocument, Headings.Heading_20_2);
            header.OutLineLevel = "2";
            header.TextContent.Add(new SimpleText(textDocument, sHeading));
            //add the header to the content
            textDocument.Content.Add(header);
            //add the toc entry text as entry to the Table of contents
            tableOfContents.InsertEntry(sTocEntry, 2);
            //Add some text to this sub chapter
            paragraph = ParagraphBuilder.CreateStandardTextParagraph(textDocument);
            paragraph.TextContent.Add(new SimpleText(textDocument, "I'm the text for the subchapter chapter!"));
            textDocument.Content.Add(paragraph);
//		ListStyle listStyle				= new ListStyle(textDocument, "TOC_LIST");
//		listStyle.AutomaticAddListLevelStyles(ListStyles.Number);
//		textDocument.Styles.Add(listStyle);
            //Save it
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                textDocument.Save(AARunMeFirstAndOnce.outPutFolder + "toc.odt", new OpenDocumentTextExporter(writer));
            }
        }
コード例 #18
0
        public void TextToOpenDocumentText()
        {
            TextDocument document = new TextDocument();

            document.Load(AARunMeFirstAndOnce.inPutFolder + "TextToOpenDocument.txt", new PlainTextImporter());
            Assert.IsNotNull(document.Content, "Must contain objects.");
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                document.Save(AARunMeFirstAndOnce.outPutFolder + "TextToOpenDocument.odt", new OpenDocumentTextExporter(writer));
            }
        }
コード例 #19
0
        public void CsvToOpenDocumentSpreadsheet()
        {
            SpreadsheetDocument document = new SpreadsheetDocument();

            document.Load(AARunMeFirstAndOnce.inPutFolder + "CsvToOpenDocument.csv", new CsvImporter());
            Assert.IsTrue(document.Content.Count == 1, "Must contain objects.");
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                document.Save(AARunMeFirstAndOnce.outPutFolder + "CsvToOpenDocument.ods", new OpenDocumentTextExporter(writer));
            }
        }
コード例 #20
0
        public void EmptyDocument()
        {
            //Create a new text document
            TextDocument document = new TextDocument();

            document.New();
            //Save empty
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                document.Save(AARunMeFirstAndOnce.outPutFolder + "empty.odt", new OpenDocumentTextExporter(writer));
            }
        }
コード例 #21
0
        public void NewBasicChartThenSetTitle()
        {
            const string        expected = "Basic Chart";
            SpreadsheetDocument doc      = new SpreadsheetDocument();

            doc.New();
            Table table = new Table(doc, "tab1", "tab1");

            for (int i = 1; i <= 1; i++)
            {
                for (int j = 1; j <= 6; j++)
                {
                    Cell cell = table.CreateCell();
                    cell.OfficeValueType = "float";
                    Paragraph paragraph = new Paragraph(doc);
                    string    text      = (j + i - 1).ToString();
                    paragraph.TextContent.Add(new SimpleText(doc, text));
                    cell.Content.Add(paragraph);
                    cell.OfficeValueType = "string";
                    cell.OfficeValue     = text;
                    table.InsertCellAt(i, j, cell);
                }
            }
            Chart      basicChart = ChartBuilder.CreateChart(table, ChartTypes.line, "A4:F8");
            ChartTitle ct         = new ChartTitle(basicChart);

            //ct.InitTitle();
            ct.SetTitle(expected);
            Assert.AreEqual(expected, ((Paragraph)ct.Content[0]).TextContent[0].Text);
            basicChart.ChartTitle = ct;
            IContent chartTitleContent = basicChart.Content.Find(o => o is ChartTitle);

            if (chartTitleContent == null)
            {
                foreach (IContent iContent in basicChart.Content)
                {
                    if (iContent is ChartTitle)
                    {
                        chartTitleContent = iContent;
                    }
                }
            }
            Assert.AreEqual(expected, ((Paragraph)((ChartTitle)chartTitleContent).Content[0]).TextContent[0].Text);
            table.InsertChartAt("H2", basicChart);
            doc.TableCollection.Add(table);
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                doc.Save(Path.Combine(AARunMeFirstAndOnce.outPutFolder, "BasicChartWithTitlesetafterwards.ods"), new OpenDocumentTextExporter(writer));
            }
        }
コード例 #22
0
        public void HeaderContentsTest1()
        {
            string       file         = AARunMeFirstAndOnce.inPutFolder + "pagestyles.odt";
            TextDocument textDocument = new TextDocument();

            using (IPackageReader reader = new OnDiskPackageReader())
            {
                textDocument.Load(file, new OpenDocumentImporter(reader));

                TextMasterPage txtMP = textDocument.TextMasterPageCollection.GetDefaultMasterPage();
                txtMP.ActivatePageHeaderAndFooter();
                txtMP.TextPageHeader.MarginLeft = "4cm";
                foreach (IContent iContent in txtMP.TextPageHeader.ContentCollection)
                {
                    if (iContent is Paragraph)
                    {
                        Assert.IsNotNull(((Paragraph)iContent).MixedContent, "Must be mixed content available.");
                        Assert.IsTrue(((Paragraph)iContent).MixedContent.Count > 0,
                                      "Must be mixed contents object inside.");
                        Assert.IsTrue(((Paragraph)iContent).MixedContent[0] is SimpleText,
                                      "First IContent has to be type of SimpleText.");
                        Assert.IsTrue(((Paragraph)iContent).MixedContent[1] is FormatedText,
                                      "Second IContent has to be type of FormatedText.");
                        // Change the simple text
                        string     changeText = "Has changed ";
                        SimpleText simpleText = ((Paragraph)iContent).MixedContent[0] as SimpleText;
                        simpleText.Text = changeText;
                    }
                    else
                    {
                        Console.WriteLine(iContent.GetType().FullName);
                    }
                }

                Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(textDocument);
                // add one extra Paragraph
                SimpleText extraText = new SimpleText(textDocument, "Some extra text...");
                paragraph.TextContent.Add(extraText);
                txtMP.TextPageHeader.ContentCollection.Add(paragraph);

                textDocument.DocumentStyles.Styles.Save(AARunMeFirstAndOnce.outPutFolder + "pagestyles_changed.xml");

                using (IPackageWriter writer = new OnDiskPackageWriter())
                {
                    textDocument.Save(AARunMeFirstAndOnce.outPutFolder + "pagestyles_changed.odt",
                                      new OpenDocumentTextExporter(writer));
                }
            }
        }
コード例 #23
0
ファイル: GraphicTest.cs プロジェクト: zhaoyin/officeOBA
        public void GraphicsTest()
        {
            TextDocument textdocument = new TextDocument();

            textdocument.New();
            Paragraph p     = ParagraphBuilder.CreateStandardTextParagraph(textdocument);
            Frame     frame = new Frame(textdocument, "frame1",
                                        "graphic1", new DiskFile(_imagefile));

            p.Content.Add(frame);
            textdocument.Content.Add(p);
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                textdocument.Save(AARunMeFirstAndOnce.outPutFolder + "grapic.odt", new OpenDocumentTextExporter(writer));
            }
        }
コード例 #24
0
ファイル: FrameTest.cs プロジェクト: zhaoyin/officeOBA
        public void FrameTestRead()
        {
            TextDocument document = new TextDocument();

            using (IPackageReader reader = new OnDiskPackageReader())
            {
                document.Load(_framefile, new OpenDocumentImporter(reader));
                Assert.IsTrue(document.Content[1].GetType() == typeof(Frame));
                Frame frame = (Frame)document.Content[1];
                Assert.IsNotNull(frame);
                using (IPackageWriter writer = new OnDiskPackageWriter())
                {
                    document.Save(_framefileSave, new OpenDocumentTextExporter(writer));
                }
            }
        }
コード例 #25
0
        public void NewChartWithAxises()
        {
            SpreadsheetDocument doc = new SpreadsheetDocument();

            using (IPackageReader reader = new OnDiskPackageReader())
            {
                doc.Load(Path.Combine(AARunMeFirstAndOnce.inPutFolder, @"testsheet.ods"), new OpenDocumentImporter(reader));
                Table table = doc.TableCollection[0];
                Chart chart = ChartBuilder.CreateChartByAxises(table, "A1:B2", ChartTypes.line, 2);
                table.InsertChartAt("I2", chart);
                doc.Content.Add(table);
                using (IPackageWriter writer = new OnDiskPackageWriter())
                {
                    doc.Save(Path.Combine(AARunMeFirstAndOnce.outPutFolder, "NewChartWithAxis.ods"), new OpenDocumentTextExporter(writer));
                }
            }
        }
コード例 #26
0
        public void TestLengend()
        {
            SpreadsheetDocument doc = new SpreadsheetDocument();

            using (IPackageReader reader = new OnDiskPackageReader())
            {
                doc.Load(Path.Combine(AARunMeFirstAndOnce.inPutFolder, @"TestChartOne.ods"), new OpenDocumentImporter(reader));
                Chart chart = (Chart)doc.EmbedObjects[0];
                chart.ChartLegend.LegendPosition = "left";
                chart.ChartLegend.SvgX           = "5cm";
                chart.ChartLegend.SvgY           = "2cm";
                using (IPackageWriter writer = new OnDiskPackageWriter())
                {
                    doc.Save(Path.Combine(AARunMeFirstAndOnce.outPutFolder, "TestLegend.ods"), new OpenDocumentTextExporter(writer));
                }
            }
        }
コード例 #27
0
        public void CreateNewChart()

        {
            SpreadsheetDocument doc = new SpreadsheetDocument();

            doc.New();
            Table table = new Table(doc, "tab1", "tab1");

            for (int i = 1; i <= 1; i++)
            {
                for (int j = 1; j <= 6; j++)
                {
                    Cell cell = table.CreateCell();
                    cell.OfficeValueType = "float";
                    Paragraph paragraph = new Paragraph(doc);
                    string    text      = (j + i - 1).ToString();
                    paragraph.TextContent.Add(new SimpleText(doc, text));
                    cell.Content.Add(paragraph);
                    cell.OfficeValueType = "string";
                    cell.OfficeValue     = text;
                    table.InsertCellAt(i, j, cell);
                }
            }

            Chart chart = ChartBuilder.CreateChartByAxisName
                              (table, ChartTypes.bar, "A1:E4", "years", "dollars");

            Assert.AreEqual(7, table.Rows[1].Cells.Count);
            Assert.AreEqual(6, table.Rows[2].Cells.Count);
            Assert.AreEqual(6, table.Rows[3].Cells.Count);
            Assert.AreEqual(6, table.Rows[4].Cells.Count);

            /*Chart chart = new Chart (table,"ch1");
             * chart.ChartType=ChartTypes.bar .ToString () ;
             * chart.XAxisName ="yeer";
             * chart.YAxisName ="dollar";
             * chart.CreateFromCellRange ("A1:E4");
             * chart.EndCellAddress ="tab1.K17";*/
            table.InsertChartAt("G2", chart);

            doc.Content.Add(table);
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                doc.Save(Path.Combine(AARunMeFirstAndOnce.outPutFolder, @"NewChartOne.ods"), new OpenDocumentTextExporter(writer));
            }
        }
コード例 #28
0
        public void LoadChartModifyTitle()
        {
            SpreadsheetDocument doc = new SpreadsheetDocument();

            using (IPackageReader reader = new OnDiskPackageReader())
            {
                doc.Load(Path.Combine(AARunMeFirstAndOnce.inPutFolder, @"TestChartOne.ods"), new OpenDocumentImporter(reader));
                IContent iContent = doc.EmbedObjects[0];
                ((Chart)iContent).ChartTitle.SetTitle("A New Title");
                ((Chart)iContent).ChartTitle.SvgX = "2cm";
                ((Chart)iContent).ChartTitle.SvgY = "0.5cm";
                using (IPackageWriter writer = new OnDiskPackageWriter())
                {
                    doc.Save(Path.Combine(AARunMeFirstAndOnce.outPutFolder, "TestTitle.ods"), new OpenDocumentTextExporter(writer));
                }
            }
        }
コード例 #29
0
        public void TestPlotArea()
        {
            SpreadsheetDocument doc = new SpreadsheetDocument();

            using (IPackageReader reader = new OnDiskPackageReader())
            {
                doc.Load(Path.Combine(AARunMeFirstAndOnce.inPutFolder, @"TestChartOne.ods"), new OpenDocumentImporter(reader));
                Chart chart = (Chart)doc.EmbedObjects[0];
                chart.ChartPlotArea.SvgX   = "1.2cm";
                chart.ChartPlotArea.SvgY   = "2.5cm";
                chart.ChartPlotArea.Width  = "5cm";
                chart.ChartPlotArea.Height = "5cm";
                using (IPackageWriter writer = new OnDiskPackageWriter())
                {
                    doc.Save(Path.Combine(AARunMeFirstAndOnce.outPutFolder, "TestPlotArea.ods"), new OpenDocumentTextExporter(writer));
                }
            }
        }
コード例 #30
0
        public void HeadingsTest()
        {
            //Create a new text document
            TextDocument document = new TextDocument();

            document.New();
            //Create a new Heading
            Header header = new Header(document, Headings.Heading);

            //Add some header text
            header.TextContent.Add(new SimpleText(document, "I'm the first headline"));
            //Add header
            document.Content.Add(header);
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                document.Save(AARunMeFirstAndOnce.outPutFolder + "Heading.odt", new OpenDocumentTextExporter(writer));
            }
        }