Ejemplo n.º 1
0
        public void CreateTableFormatedText()
        {
            //Create new spreadsheet document
            SpreadsheetDocument spreadsheetDocument = new SpreadsheetDocument();

            spreadsheetDocument.New();
            //Create a new table
            Table table = new Table(spreadsheetDocument, "First", "tablefirst");
            //Create a new cell, without any extra styles
            Cell cell = table.CreateCell();
            //cell.OfficeValueType					= "string";
            //Set full border
            //cell.CellStyle.CellProperties.Border	= Border.NormalSolid;
            //Add a paragraph to this cell
            Paragraph paragraph = ParagraphBuilder.CreateSpreadsheetParagraph(
                spreadsheetDocument);
            //Create some Formated text
            FormatedText fText = new FormatedText(spreadsheetDocument, "T1", "Some Text");

            //fText.TextStyle.TextProperties.Bold		 = "bold";
            fText.TextStyle.TextProperties.Underline = LineStyles.dotted;
            //Add formated text
            paragraph.TextContent.Add(fText);
            //Add paragraph to the cell
            cell.Content.Add(paragraph);
            //Insert the cell at row index 2 and column index 3
            //All need rows, columns and cells below the given
            //indexes will be build automatically.
            table.InsertCellAt(2, 3, cell);
            //Insert table into the spreadsheet document
            spreadsheetDocument.TableCollection.Add(table);
            spreadsheetDocument.SaveTo(AARunMeFirstAndOnce.outPutFolder + "formated.ods");
        }
Ejemplo n.º 2
0
        public void CellParagraphTest()
        {
            TextDocument doc = new TextDocument();

            doc.New();

            Table table = new Table(doc, "table1");

            table.Init(5, 3, 16.99);

            foreach (Row r in table.Rows)
            {
                foreach (Cell c in r.Cells)
                {
                    c.InsertText("Hello");
                }
            }

            Paragraph p = new Paragraph(doc, "P1");

            FormatedText ft = new FormatedText(p, "T1", "Hello World");

            ((TextStyle)ft.Style).Properties.Italic = "italic";

            p.TextContent.Add(ft);

            table.Rows[0].Cells[0].Content.Add(p);

            doc.Content.Add(table);

            doc.SaveTo("tablewithstyles.odt");
        }
Ejemplo n.º 3
0
        public void CellParagraphTest()
        {
            TextDocument doc		= new TextDocument();
            doc.New();

            Table table				= new Table(doc, "table1");
            table.Init(5, 3, 16.99);

            foreach(Row r in table.Rows)
                foreach(Cell c in r.Cells)
                    c.InsertText("Hello");

            Paragraph p				= new Paragraph(doc, "P1");

            FormatedText ft			= new FormatedText(p, "T1", "Hello World");

            ((TextStyle)ft.Style).Properties.Italic = "italic";

            p.TextContent.Add(ft);

            table.Rows[0].Cells[0].Content.Add(p);

            doc.Content.Add(table);

            doc.SaveTo("tablewithstyles.odt");
        }
Ejemplo n.º 4
0
        public void ParagraphContentTest()
        {
            TextDocument td = new TextDocument();

            td.New();

            Paragraph p = new Paragraph(td, "P1");

            ((ParagraphStyle)p.Style).Properties.Alignment = TextAlignments.end.ToString();
            //Add some content
            p.TextContent.Add(new SimpleText((IContent)p, "Hallo i'm simple text!"));
            Assert.IsTrue(p.TextContent.Count > 0, "Must be greater than zero!");
            FormatedText ft = new FormatedText((IContent)p, "T1", " \"And < > &     i'm formated text!");

            ((TextStyle)ft.Style).Properties.Bold   = "bold";
            ((TextStyle)ft.Style).Properties.Italic = "italic";
            ((TextStyle)ft.Style).Properties.SetUnderlineStyles(
                LineStyles.wave, LineWidths.bold.ToString(), "#A1B1C2");
//			((TextStyle)ft.Style).Properties.Underline = LineStyles.dotted;
//			((TextStyle)ft.Style).Properties.UnderlineColor = "font-color";
//			((TextStyle)ft.Style).Properties.UnderlineWidth = LineWidths.auto.ToString();
            p.TextContent.Add(ft);
            Assert.IsTrue(p.TextContent.Count == 2, "Must be two!");
            //Add as document content
            td.Content.Add(p);
            //Console.WriteLine(td.XmlDoc.OuterXml);
            //Generate and save
            td.SaveTo("ParagraphTest.odt");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates the formated text.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        public FormatedText CreateFormatedText(IDocument document, XmlNode node)
        {
            try
            {
                //Create a new FormatedText object
                FormatedText    formatedText = new FormatedText(document, node);
                ITextCollection iTextColl    = new ITextCollection();
                formatedText.Document = document;
                formatedText.Node     = node;
                //Recieve a TextStyle

                IStyle textStyle = document.Styles.GetStyleByName(formatedText.StyleName);

                if (textStyle != null)
                {
                    formatedText.Style = textStyle;
                }
                else
                {
                    IStyle iStyle = document.CommonStyles.GetStyleByName(formatedText.StyleName);
                    if (iStyle == null)
                    {
                        if (OnWarning != null)
                        {
                            AODLWarning warning = new AODLWarning("A TextStyle for the FormatedText object wasn't found.");
                            warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
                            warning.Node     = node;
                            OnWarning(warning);
                        }
                    }
                }

                //Ceck for more IText object
                foreach (XmlNode iTextNode in node.ChildNodes)
                {
                    IText iText = this.CreateTextObject(document, iTextNode.CloneNode(true));
                    if (iText != null)
                    {
                        iTextColl.Add(iText);
                    }
                    else
                    {
                        iTextColl.Add(new UnknownTextContent(document, iTextNode) as IText);
                    }
                }

                formatedText.Node.InnerText = "";

                foreach (IText iText in iTextColl)
                {
                    formatedText.TextContent.Add(iText);
                }

                return(formatedText);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Create a deep clone of this FormatedText object.
        /// </summary>
        /// <remarks>A possible Attached Style wouldn't be cloned!</remarks>
        /// <returns>
        /// A clone of this object.
        /// </returns>
        public object Clone()
        {
            FormatedText formatedTextClone = null;

            if (this.Document != null && this.Node != null)
            {
                TextContentProcessor tcp = new TextContentProcessor();
                formatedTextClone = tcp.CreateFormatedText(
                    this.Document, this.Node.CloneNode(true));
            }

            return(formatedTextClone);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create a deep clone of this FormatedText object.
        /// </summary>
        /// <remarks>A possible Attached Style wouldn't be cloned!</remarks>
        /// <returns>
        /// A clone of this object.
        /// </returns>
        public object Clone()
        {
            FormatedText formatedTextClone = null;

            if (Document != null && Node != null)
            {
                TextContentProcessor tcp = new TextContentProcessor();
                formatedTextClone = tcp.CreateFormatedText(
                    Document, new XElement(Node));
            }

            return(formatedTextClone);
        }
Ejemplo n.º 8
0
        public static void AddCell(this Table tbl, int row, int col, string text, Color back)
        {
            var c = tbl.CreateCell();

            c.CellStyle = new CellStyle(tbl.Document)
            {
                CellProperties = { BackgroundColor = back.ToHex() }
            };
            var p = ParagraphBuilder.CreateSpreadsheetParagraph(tbl.Document);
            var t = new FormatedText(tbl.Document, "t" + row + col, text);

            p.TextContent.Add(t);
            c.Content.Add(p);
            tbl.InsertCellAt(row, col, c);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates the formated text.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        public FormatedText CreateFormatedText(IDocument document, XElement node)
        {
            //Create a new FormatedText object
            FormatedText    formatedText = new FormatedText(document, node);
            ITextCollection iTextColl    = new ITextCollection();

            formatedText.Document = document;
            formatedText.Node     = node;
            //Recieve a TextStyle

            IStyle textStyle = document.Styles.GetStyleByName(formatedText.StyleName);

            if (textStyle != null)
            {
                formatedText.Style = textStyle;
            }
            //else
            //{
            //	IStyle iStyle				= document.CommonStyles.GetStyleByName(formatedText.StyleName);
            //}

            //Ceck for more IText object
            foreach (XNode iTextNode in node.Nodes())
            {
                XNode clone = iTextNode is XElement
                                  ? (XNode) new XElement((XElement)iTextNode)
                                  : new XText((XText)iTextNode);
                IText iText = CreateTextObject(document, clone);
                if (iText != null)
                {
                    iTextColl.Add(iText);
                }
                else
                {
                    iTextColl.Add(new UnknownTextContent(document, (XElement)iTextNode));
                }
            }

            formatedText.Node.Value = "";

            foreach (IText iText in iTextColl)
            {
                formatedText.TextContent.Add(iText);
            }

            return(formatedText);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="title"></param>
        public void SetTitle(String title)
        {
            Cell titolo = new Cell(document, "cell001");

            titolo.OfficeValueType = "string";
            Paragraph    titoloParagraph = ParagraphBuilder.CreateSpreadsheetParagraph(document);
            FormatedText fText           = new FormatedText(document, "T1", title);

            fText.TextStyle.TextProperties.Bold     = "bold";
            fText.TextStyle.TextProperties.FontSize = "20pt";
            titoloParagraph.TextContent.Add(fText);
            titolo.Content.Add(titoloParagraph);
            table.Rows.Add(new Row(table));
            table.Rows[0].Cells.Add(titolo);
            this.title = title;
            currentRow++;
        }
Ejemplo n.º 11
0
        public void ParagraphFormatedText()
        {
            //Create a new text document
            TextDocument document = new TextDocument();

            document.New();
            //Create a standard paragraph using the ParagraphBuilder
            Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
            //Add some formated text
            FormatedText formText = new FormatedText(document, "T1", "Some formated text!");

            formText.TextStyle.TextProperties.Bold = "bold";
            paragraph.TextContent.Add(formText);
            //Add the paragraph to the document
            document.Content.Add(paragraph);
            //Save empty
            document.SaveTo(AARunMeFirstAndOnce.outPutFolder + "formated.odt");
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates the formated text.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        public FormatedText CreateFormatedText(IDocument document, XmlNode node)
        {
            //Create a new FormatedText object
            FormatedText    formatedText = new FormatedText(document, node);
            ITextCollection iTextColl    = new ITextCollection();

            formatedText.Document = document;
            formatedText.Node     = node;
            //Recieve a TextStyle

            IStyle textStyle = document.Styles.GetStyleByName(formatedText.StyleName);

            if (textStyle != null)
            {
                formatedText.Style = textStyle;
            }
            //else
            //{
            //	IStyle iStyle				= document.CommonStyles.GetStyleByName(formatedText.StyleName);
            //}

            //Ceck for more IText object
            foreach (XmlNode iTextNode in node.ChildNodes)
            {
                IText iText = this.CreateTextObject(document, iTextNode.CloneNode(true));
                if (iText != null)
                {
                    iTextColl.Add(iText);
                }
                else
                {
                    iTextColl.Add(new UnknownTextContent(document, iTextNode) as IText);
                }
            }

            formatedText.Node.InnerText = "";

            foreach (IText iText in iTextColl)
            {
                formatedText.TextContent.Add(iText);
            }

            return(formatedText);
        }
Ejemplo n.º 13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="row"></param>
 private void SetColumnsName(DataRow row)
 {
     table.Rows.Add(new Row(table));
     foreach (String columnName in row.ItemArray)
     {
         Cell columnHeader = new Cell(document, "cell003");
         columnHeader.OfficeValueType = "string";
         columnHeader.CellStyle.CellProperties.Border          = Border.HeavySolid;
         columnHeader.CellStyle.CellProperties.BackgroundColor = "#D0B1A1";
         Paragraph    titoloParagraph = ParagraphBuilder.CreateSpreadsheetParagraph(document);
         FormatedText fText           = new FormatedText(document, "T3", columnName);
         fText.TextStyle.TextProperties.Bold     = "bold";
         fText.TextStyle.TextProperties.FontSize = "10pt";
         titoloParagraph.TextContent.Add(fText);
         columnHeader.Content.Add(titoloParagraph);
         table.Rows[currentRow].Cells.Add(columnHeader);
     }
     currentRow++;
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Metodo per l'impostazione delle informazioni aggiuntive di un report
        /// </summary>
        /// <param name="additionalInformation"></param>
        /// <param name="sheet"></param>
        /// <param name="reportKey"></param>
        private void SetAdditionalInformation(String additionalInformation, Table sheet, String reportKey)
        {
            Cell addInfoCell = new Cell(sheet.Document, "cell002");

            addInfoCell.OfficeValueType = "string";
            Paragraph    subTitleParagraph = ParagraphBuilder.CreateSpreadsheetParagraph(sheet.Document);
            FormatedText fText             = new FormatedText(sheet.Document, "T2", additionalInformation);

            fText.TextStyle.TextProperties.Bold     = "bold";
            fText.TextStyle.TextProperties.FontSize = "15pt";
            if (reportKey == "RegistroAccessiPublish")
            {
                fText.TextStyle.TextProperties.Bold = String.Empty;
                addInfoCell.CellStyle.CellProperties.BackgroundColor = "#DDDDDD";
            }
            subTitleParagraph.TextContent.Add(fText);
            addInfoCell.Content.Add(subTitleParagraph);
            sheet.Rows.Add(new Row(sheet));
            sheet.Rows[2].Cells.Add(addInfoCell);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Metodo per l'impostazione del titolo di un report
        /// </summary>
        /// <param name="title">Titolo da assegnare al foglio</param>
        /// <param name="sheet">Foglio a cui aggiungere il titolo</param>
        private void SetTitle(String title, Table sheet, String reportKey)
        {
            Cell titleCell = new Cell(sheet.Document, "cell001");

            titleCell.OfficeValueType = "string";
            Paragraph    titleParagraph = ParagraphBuilder.CreateSpreadsheetParagraph(sheet.Document);
            FormatedText fText          = new FormatedText(sheet.Document, "T1", title);

            fText.TextStyle.TextProperties.Bold     = "bold";
            fText.TextStyle.TextProperties.FontSize = "16pt";
            if (reportKey == "RegistroAccessiPublish")
            {
                fText.TextStyle.TextProperties.Bold = String.Empty;
                titleCell.CellStyle.CellProperties.BackgroundColor = "#DDDDDD";
            }
            titleParagraph.TextContent.Add(fText);
            titleCell.Content.Add(titleParagraph);
            sheet.Rows.Add(new Row(sheet));
            sheet.Rows[0].Cells.Add(titleCell);
        }
Ejemplo n.º 16
0
        public void CreateTableFormatedText()
        {
            //Create new spreadsheet document
            _spreadsheetDocument3 = new SpreadsheetDocument();
            using (IPackageReader reader = new OnDiskPackageReader())
            {
                _spreadsheetDocument3.Load(AARunMeFirstAndOnce.inPutFolder + @"blank.ods", new OpenDocumentImporter(reader));
            }
            //Create a new table
            Table table = new Table(_spreadsheetDocument3, "First", "tablefirst");

            table.Rows.Add(new Row(table));
            //Create a new cell, without any extra styles
            Cell cell = table.CreateCell();

            cell.OfficeValueType = "string";
            //Set full border
            //cell.CellStyle.CellProperties.Border	= Border.NormalSolid;
            //Add a paragraph to this cell
            Paragraph paragraph = ParagraphBuilder.CreateSpreadsheetParagraph(
                _spreadsheetDocument3);
            //Create some Formated text
            FormatedText fText = new FormatedText(_spreadsheetDocument3, "T1", "Some Text");

            //fText.TextStyle.TextProperties.Bold		 = "bold";
            fText.TextStyle.TextProperties.Underline = LineStyles.dotted;
            //Add formated text
            paragraph.TextContent.Add(fText);
            //Add paragraph to the cell
            cell.Content.Add(paragraph);
            //Insert the cell at row index 2 and column index 3
            //All need rows, columns and cells below the given
            //indexes will be build automatically.
            table.InsertCellAt(2, 3, cell);
            //Insert table into the spreadsheet document
            _spreadsheetDocument3.TableCollection.Add(table);
            // Test inserted content
            Object insertedText = ((Paragraph)_spreadsheetDocument3.TableCollection[0].Rows[2].Cells[3].Content[0]).TextContent[0];

            Assert.AreEqual(fText, insertedText as FormatedText);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Metodo per l'aggiunta dell'header ad un foglio Excel
        /// </summary>
        /// <param name="header">Header da aggiungere</param>
        /// <param name="sheet">Foglio a cui aggiungere l'instestazione</param>
        private void AddHeaderRow(DocsPaVO.Report.HeaderColumnCollection header, Table sheet, String reportKey)
        {
            sheet.Rows.Add(new Row(sheet));
            int actualRow = sheet.Rows.Count - 1;
            int actualCol = 0;

            foreach (var headerColumn in header)
            {
                Cell headerCell = new Cell(sheet.Document, "cell003");
                headerCell.OfficeValueType = "string";
                headerCell.CellStyle.CellProperties.Border          = Border.HeavySolid;
                headerCell.CellStyle.CellProperties.BackgroundColor = "#D0B1A1";

                Paragraph    paragraph = ParagraphBuilder.CreateSpreadsheetParagraph(sheet.Document);
                FormatedText fText     = new FormatedText(sheet.Document, "T3", headerColumn.ColumnName);
                fText.TextStyle.TextProperties.Bold     = "bold";
                fText.TextStyle.TextProperties.FontName = "Arial";
                fText.TextStyle.TextProperties.FontSize = "11pt";
                paragraph.TextContent.Add(fText);
                headerCell.Content.Add(paragraph);
                sheet.Rows[actualRow].Cells.Add(headerCell);
                if (reportKey == "RegistroAccessiPublish")
                {
                    headerCell.CellStyle.CellProperties.BackgroundColor = String.Empty;
                    fText.TextStyle.TextProperties.FontName             = "ArialNarrow";
                    fText.TextStyle.TextProperties.FontColor            = "#006699";
                    sheet.ColumnCollection[actualCol].ColumnStyle.ColumnProperties.Width = String.Format("{0}px", (headerColumn.ColumnSize * 2).ToString());

                    Cell titleCell    = new Cell(sheet.Document, "cell001");
                    Cell subTitleCell = new Cell(sheet.Document, "cell002");
                    Cell addInfoCell  = new Cell(sheet.Document, "cell000");
                    titleCell.CellStyle.CellProperties.BackgroundColor    = "#DDDDDD";
                    subTitleCell.CellStyle.CellProperties.BackgroundColor = "#DDDDDD";
                    addInfoCell.CellStyle.CellProperties.BackgroundColor  = "#DDDDDD";
                    sheet.Rows[0].Cells.Add(titleCell);
                    sheet.Rows[1].Cells.Add(subTitleCell);
                    sheet.Rows[2].Cells.Add(addInfoCell);
                }
                actualCol++;
            }
        }
Ejemplo n.º 18
0
        public void HeaderAndFooterCreateTest()
        {
            TextDocument document = new TextDocument();

            document.New();
            // get default mast page layout
            TextMasterPage txtMP = document.TextMasterPageCollection.GetDefaultMasterPage();

            // IMPORTANT: activating header and footer usage
            // has to be called before setting there layout properties!
            txtMP.ActivatePageHeaderAndFooter();
            Console.WriteLine(txtMP.TextPageHeader.MarginLeft);
            // set page header layout
//			txtMP.TextPageHeader.MarginLeft = "4cm";
//			// set text page layout
//			txtMP.TextPageLayout.MarginLeft = "6cm";
//			// create a paragraph for the header
            Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
            // add some formated text
            // TODO: FIXME there is a bug with the text styles for header and footer!
            FormatedText formText = new FormatedText(document, "T1", "Some formated text in the page header ...");

            formText.TextStyle.TextProperties.Bold = "bold";
            paragraph.TextContent.Add(formText);
            // add this paragraph to the page header
            txtMP.TextPageHeader.ContentCollection.Add(paragraph);
            // create a paragraph collection with some text for the document
//			ParagraphCollection pColl = AODL.Document.Content.Text.ParagraphBuilder.CreateParagraphCollection(
//				document,
//				"Some text in here ... \n\n... with a modified master page :)",
//				true,
//				ParagraphBuilder.ParagraphSeperator);
//			// add the paragraphs
//			foreach(AODL.Document.Content.Text.Paragraph p in pColl)
//				document.Content.Add(p);
            // save the document
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                document.Save(AARunMeFirstAndOnce.outPutFolder + "text_master_page_1.odt", new OpenDocumentTextExporter(writer));
            }
        }
Ejemplo n.º 19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="subtitle"></param>
 public void SetSubtitle(String subtitle)
 {
     if (!title.Equals(""))
     {
         Cell sottoTitolo = new Cell(document, "cell002");
         sottoTitolo.OfficeValueType = "string";
         Paragraph    sottoTitoloParagraph = ParagraphBuilder.CreateSpreadsheetParagraph(document);
         FormatedText fText = new FormatedText(document, "T2", subtitle);
         fText.TextStyle.TextProperties.Bold     = "bold";
         fText.TextStyle.TextProperties.FontSize = "15pt";
         sottoTitoloParagraph.TextContent.Add(fText);
         sottoTitolo.Content.Add(sottoTitoloParagraph);
         table.Rows.Add(new Row(table));
         table.Rows[1].Cells.Add(sottoTitolo);
         currentRow++;
     }
     else
     {
         throw new Exception("Try to insert subtitle before title, please insert title first");
     }
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Metodo per l'aggiunta delle righe al report
 /// </summary>
 /// <param name="sheet">Foglio a cui aggiungere le righe</param>
 /// <param name="reportRows">Righe del report</param>
 private void AddReportData(Table sheet, DocsPaVO.Report.ReportMapRow reportRows)
 {
     foreach (var row in reportRows.Rows)
     {
         sheet.Rows.Add(new Row(sheet));
         foreach (var column in row.Columns)
         {
             Cell columnItem = new Cell(sheet.Document, "cell004");
             columnItem.OfficeValueType = "string";
             columnItem.CellStyle.CellProperties.Border = Border.HeavySolid;
             Paragraph    paragraph = ParagraphBuilder.CreateSpreadsheetParagraph(sheet.Document);
             FormatedText fText     = new FormatedText(sheet.Document, "T4", column.Value);
             //fText.TextStyle.TextProperties.Bold = "bold";
             fText.TextStyle.TextProperties.FontSize = "11pt";
             paragraph.TextContent.Add(fText);
             columnItem.Content.Add(paragraph);
             int rowNum = sheet.Rows.Count - 1;
             sheet.Rows[rowNum].Cells.Add(columnItem);
         }
     }
 }
Ejemplo n.º 21
0
        /// <summary>
        /// First Row of data must contains columns' names
        /// </summary>
        /// <param name="data"></param>
        public void SetData(DataSet data)
        {
            int dataRows = 0;

            if (data.Tables[0].Rows[0] != null)
            {
                SetColumnsName(data.Tables[0].Rows[0]);

                foreach (DataRow row in data.Tables[0].Rows)
                {
                    if (dataRows != 0)
                    {
                        table.Rows.Add(new Row(table));
                        foreach (String columnName in row.ItemArray)
                        {
                            Cell columnItem = new Cell(document, "cell004");
                            columnItem.OfficeValueType = "string";
                            columnItem.CellStyle.CellProperties.Border = Border.HeavySolid;
                            //columnItem.CellStyle.CellProperties.BackgroundColor = "#D0B1A1";
                            Paragraph    titoloParagraph = ParagraphBuilder.CreateSpreadsheetParagraph(document);
                            FormatedText fText           = new FormatedText(document, "T4", columnName);
                            fText.TextStyle.TextProperties.Bold     = "bold";
                            fText.TextStyle.TextProperties.FontSize = "10pt";
                            titoloParagraph.TextContent.Add(fText);
                            columnItem.Content.Add(titoloParagraph);
                            table.Rows[currentRow].Cells.Add(columnItem);
                        }
                        currentRow++;
                    }
                    dataRows++;
                }
            }
            else
            {
                throw new Exception("Columns' names not found");
            }
        }
Ejemplo n.º 22
0
        public void FooterAndHeader()
        {
            //Create a new document
            TextDocument td = new TextDocument();

            td.New();
            //Create a new paragraph
            Paragraph p = new Paragraph(td, "P1");
            //Create some formated text
            FormatedText ftext = new FormatedText(p, "F1", "Im the Header");

            ((TextStyle)ftext.Style).Properties.Italic = "italic";
            //add the text
            p.TextContent.Add(ftext);
            //Insert paragraph as header
            td.InsertHeader(p);
            //New paragraph
            p = new Paragraph(td, ParentStyles.Standard,
                              "I'm the Footer");
            //Insert paragraph as footer
            td.InsertFooter(p);
            //Save
            td.SaveTo("Header_Footer.odt");
        }
Ejemplo n.º 23
0
        public void CreateOdtHtmlFile(Boolean Copy, DataTable[] Blanks, Double[] Fund, int type, string filepath, Int32[] Indexes, DateTime time)
        {
            TextDocument Document = new TextDocument();

            Document.Load("template//report.odt");
            int     tableId = 0;
            Boolean find    = false;

            for (int i = 0; i < Document.Content.Count; i++)
            {
                Paragraph p = Document.Content[i] as Paragraph;

                for (int j = 0; j < p.TextContent.Count; j++)
                {
                    string temp = p.TextContent[j].Text;

                    if (temp != null)
                    {
                        if (temp.Contains("date"))
                        {
                            temp = temp.Replace("date", time.ToString("d"));
                            FormatedText ft = p.TextContent[j] as FormatedText;
                            ft.Text = temp;
                            ft.TextContent[0].Text = temp;
                        }
                        else if (temp.Contains("month"))
                        {
                            temp = temp.Replace("month", System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(time.Month - 1).ToLower());
                            FormatedText ft = p.TextContent[j] as FormatedText;
                            ft.Text = temp;
                            ft.TextContent[0].Text = temp;
                        }
                        else if (temp.Contains("table"))
                        {
                            find = true;
                            break;
                        }
                    }
                }

                if (find)
                {
                    break;
                }

                tableId++;
            }

            Document.Content.RemoveAt(tableId);

            int rowCount   = Blanks[0].Rows.Count + Blanks[1].Rows.Count + Blanks[2].Rows.Count + 8;
            int currentRow = 0;

            if (Blanks[0].Rows.Count == 0)
            {
                rowCount -= 2;
            }
            if (Blanks[1].Rows.Count == 0)
            {
                rowCount -= 2;
            }
            if (Blanks[2].Rows.Count == 0)
            {
                rowCount -= 2;
            }

            Table table = TableBuilder.CreateTextDocumentTable(Document, "table", "table", rowCount, 4, 17, false, true);

            table.TableStyle.TableProperties.Align = TextAlignments.justify.ToString();
            table.ColumnCollection[0].ColumnStyle.ColumnProperties.Width = "1cm";
            table.ColumnCollection[1].ColumnStyle.ColumnProperties.Width = "6cm";
            table.ColumnCollection[2].ColumnStyle.ColumnProperties.Width = "6cm";
            table.ColumnCollection[3].ColumnStyle.ColumnProperties.Width = "4cm";

            Paragraph columnName1 = ParagraphBuilder.CreateStandardTextParagraph(Document);

            columnName1.TextContent.Add(new SimpleText(Document, "№"));
            table.Rows[currentRow].Cells[0].Content.Add(columnName1);
            Paragraph columnName2 = ParagraphBuilder.CreateStandardTextParagraph(Document);

            columnName2.TextContent.Add(new SimpleText(Document, "Ф.И.О."));
            table.Rows[currentRow].Cells[1].Content.Add(columnName2);
            Paragraph columnName3 = ParagraphBuilder.CreateStandardTextParagraph(Document);

            columnName3.TextContent.Add(new SimpleText(Document, "Должность"));
            table.Rows[currentRow].Cells[2].Content.Add(columnName3);
            Paragraph columnName4 = ParagraphBuilder.CreateStandardTextParagraph(Document);

            columnName4.TextContent.Add(new SimpleText(Document, "Размер премии (руб.)"));
            table.Rows[currentRow].Cells[3].Content.Add(columnName4);

            currentRow++;

            if (Blanks[0].Rows.Count != 0)
            {
                DataView dv = Blanks[0].DefaultView;
                dv.Sort = "[ФИО] ASC";
                DataTable Blank = dv.ToTable();

                Paragraph  budget = ParagraphBuilder.CreateStandardTextParagraph(Document);
                SimpleText header = new SimpleText(Document, "По бюджетной форме");
                budget.TextContent.Add(header);
                budget.Style = Document.CommonStyles.Single(x => x.StyleName == "Заголовоктаблицы") as ParagraphStyle;
                table.Rows[currentRow].Cells[0].Content.Add(budget);

                // Сохраняем xml код ячеек которые будут объеднены,
                // чтобы удалить оставшуюся информацию после объединения

                String xmlCell1 = table.Rows[currentRow].Cells[1].Node.OuterXml;
                String xmlCell2 = table.Rows[currentRow].Cells[2].Node.OuterXml;
                String xmlCell3 = table.Rows[currentRow].Cells[3].Node.OuterXml;

                // Объединение ячеек
                table.Rows[currentRow].MergeCells(Document, 0, 4, true);

                // Удаление остаточных данных
                String innerXml = table.Rows[currentRow].Node.InnerXml;
                innerXml = innerXml.Replace(xmlCell1, "");
                innerXml = innerXml.Replace(xmlCell2, "");
                innerXml = innerXml.Replace(xmlCell3, "");
                table.Rows[currentRow].Node.InnerXml = innerXml;

                currentRow++;
                int budgetId = 1;

                foreach (DataRow row in Blank.Rows)
                {
                    Paragraph columnBudget1 = ParagraphBuilder.CreateStandardTextParagraph(Document);
                    columnBudget1.TextContent.Add(new SimpleText(Document, Convert.ToString(budgetId)));
                    table.Rows[currentRow].Cells[0].Content.Add(columnBudget1);
                    Paragraph columnBudget2 = ParagraphBuilder.CreateStandardTextParagraph(Document);
                    columnBudget2.TextContent.Add(new SimpleText(Document, row[Indexes[0]].ToString()));
                    table.Rows[currentRow].Cells[1].Content.Add(columnBudget2);
                    Paragraph columnBudget3 = ParagraphBuilder.CreateStandardTextParagraph(Document);
                    columnBudget3.TextContent.Add(new SimpleText(Document, row[Indexes[1]].ToString()));
                    table.Rows[currentRow].Cells[2].Content.Add(columnBudget3);
                    Paragraph columnBudget4 = ParagraphBuilder.CreateStandardTextParagraph(Document);
                    columnBudget4.TextContent.Add(new SimpleText(Document, row[Indexes[2]].ToString()));
                    table.Rows[currentRow].Cells[3].Content.Add(columnBudget4);

                    currentRow++;
                    budgetId++;
                }

                Paragraph result = ParagraphBuilder.CreateStandardTextParagraph(Document);
                result.TextContent.Add(new SimpleText(Document, "Итого по бюджетной форме:"));
                table.Rows[currentRow].Cells[0].Content.Add(result);
                Paragraph sum = ParagraphBuilder.CreateStandardTextParagraph(Document);
                sum.TextContent.Add(new SimpleText(Document, Fund[0].ToString()));
                table.Rows[currentRow].Cells[3].Content.Add(sum);

                // Сохраняем xml код ячеек которые будут объеднены,
                // чтобы удалить оставшуюся информацию после объединения

                xmlCell1 = table.Rows[currentRow].Cells[1].Node.OuterXml;
                xmlCell2 = table.Rows[currentRow].Cells[2].Node.OuterXml;

                // объединение ячеек
                table.Rows[currentRow].MergeCells(Document, 0, 3, true);

                // Удаление остаточных данных
                innerXml = table.Rows[currentRow].Node.InnerXml;
                innerXml = innerXml.Replace(xmlCell1, "");
                innerXml = innerXml.Replace(xmlCell2, "");

                // Перемещаем метку объедененной ячейки
                innerXml = innerXml.Replace("<table:covered-table-cell xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" />", "");
                String mergedCellXml = table.Rows[currentRow].Cells[0].Node.OuterXml;
                innerXml = innerXml.Replace(mergedCellXml, mergedCellXml +
                                            "<table:covered-table-cell xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" />");
                table.Rows[currentRow].Node.InnerXml = innerXml;

                currentRow++;
            }

            if (Blanks[1].Rows.Count != 0)
            {
                DataView dv = Blanks[1].DefaultView;
                dv.Sort = "[ФИО] ASC";
                DataTable Blank = dv.ToTable();

                Paragraph  paid   = ParagraphBuilder.CreateStandardTextParagraph(Document);
                SimpleText header = new SimpleText(Document, "По платной форме");
                paid.TextContent.Add(header);
                paid.Style = Document.CommonStyles.Single(x => x.StyleName == "Заголовоктаблицы") as ParagraphStyle;
                table.Rows[currentRow].Cells[0].Content.Add(paid);

                // Сохраняем xml код ячеек которые будут объеднены,
                // чтобы удалить оставшуюся информацию после объединения

                String xmlCell1 = table.Rows[currentRow].Cells[1].Node.OuterXml;
                String xmlCell2 = table.Rows[currentRow].Cells[2].Node.OuterXml;
                String xmlCell3 = table.Rows[currentRow].Cells[3].Node.OuterXml;

                // Объединение ячеек
                table.Rows[currentRow].MergeCells(Document, 0, 4, true);

                // Удаление остаточных данных
                String innerXml = table.Rows[currentRow].Node.InnerXml;
                innerXml = innerXml.Replace(xmlCell1, "");
                innerXml = innerXml.Replace(xmlCell2, "");
                innerXml = innerXml.Replace(xmlCell3, "");
                table.Rows[currentRow].Node.InnerXml = innerXml;

                currentRow++;
                int paidId = 1;

                foreach (DataRow row in Blank.Rows)
                {
                    Paragraph columnPaid1 = ParagraphBuilder.CreateStandardTextParagraph(Document);
                    columnPaid1.TextContent.Add(new SimpleText(Document, Convert.ToString(paidId)));
                    table.Rows[currentRow].Cells[0].Content.Add(columnPaid1);
                    Paragraph columnPaid2 = ParagraphBuilder.CreateStandardTextParagraph(Document);
                    columnPaid2.TextContent.Add(new SimpleText(Document, row[Indexes[0]].ToString()));
                    table.Rows[currentRow].Cells[1].Content.Add(columnPaid2);
                    Paragraph columnPaid3 = ParagraphBuilder.CreateStandardTextParagraph(Document);
                    columnPaid3.TextContent.Add(new SimpleText(Document, row[Indexes[1]].ToString()));
                    table.Rows[currentRow].Cells[2].Content.Add(columnPaid3);
                    Paragraph columnPaid4 = ParagraphBuilder.CreateStandardTextParagraph(Document);
                    columnPaid4.TextContent.Add(new SimpleText(Document, row[Indexes[2]].ToString()));
                    table.Rows[currentRow].Cells[3].Content.Add(columnPaid4);

                    currentRow++;
                    paidId++;
                }

                Paragraph result = ParagraphBuilder.CreateStandardTextParagraph(Document);
                result.TextContent.Add(new SimpleText(Document, "Итого по платной форме:"));
                table.Rows[currentRow].Cells[0].Content.Add(result);
                Paragraph sum = ParagraphBuilder.CreateStandardTextParagraph(Document);
                sum.TextContent.Add(new SimpleText(Document, Fund[1].ToString()));
                table.Rows[currentRow].Cells[3].Content.Add(sum);

                // Сохраняем xml код ячеек которые будут объеднены,
                // чтобы удалить оставшуюся информацию после объединения

                xmlCell1 = table.Rows[currentRow].Cells[1].Node.OuterXml;
                xmlCell2 = table.Rows[currentRow].Cells[2].Node.OuterXml;

                // объединение ячеек
                table.Rows[currentRow].MergeCells(Document, 0, 3, true);

                // Удаление остаточных данных
                innerXml = table.Rows[currentRow].Node.InnerXml;
                innerXml = innerXml.Replace(xmlCell1, "");
                innerXml = innerXml.Replace(xmlCell2, "");

                // Перемещаем метку объедененной ячейки
                innerXml = innerXml.Replace("<table:covered-table-cell xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" />", "");
                String mergedCellXml = table.Rows[currentRow].Cells[0].Node.OuterXml;
                innerXml = innerXml.Replace(mergedCellXml, mergedCellXml +
                                            "<table:covered-table-cell xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" />");
                table.Rows[currentRow].Node.InnerXml = innerXml;

                currentRow++;
            }

            if (Blanks[2].Rows.Count != 0)
            {
                DataView dv = Blanks[2].DefaultView;
                dv.Sort = "[ФИО] ASC";
                DataTable Blank = dv.ToTable();

                Paragraph  paragraph = ParagraphBuilder.CreateStandardTextParagraph(Document);
                SimpleText header    = new SimpleText(Document, "По  §54");
                paragraph.TextContent.Add(header);
                paragraph.Style = Document.CommonStyles.Single(x => x.StyleName == "Заголовоктаблицы") as ParagraphStyle;
                table.Rows[currentRow].Cells[0].Content.Add(paragraph);

                // Сохраняем xml код ячеек которые будут объеднены,
                // чтобы удалить оставшуюся информацию после объединения

                String xmlCell1 = table.Rows[currentRow].Cells[1].Node.OuterXml;
                String xmlCell2 = table.Rows[currentRow].Cells[2].Node.OuterXml;
                String xmlCell3 = table.Rows[currentRow].Cells[3].Node.OuterXml;

                // Объединение ячеек
                table.Rows[currentRow].MergeCells(Document, 0, 4, true);

                // Удаление остаточных данных
                String innerXml = table.Rows[currentRow].Node.InnerXml;
                innerXml = innerXml.Replace(xmlCell1, "");
                innerXml = innerXml.Replace(xmlCell2, "");
                innerXml = innerXml.Replace(xmlCell3, "");
                table.Rows[currentRow].Node.InnerXml = innerXml;

                currentRow++;
                int paragraphId = 1;

                foreach (DataRow row in Blank.Rows)
                {
                    Paragraph columnParagraph1 = ParagraphBuilder.CreateStandardTextParagraph(Document);
                    columnParagraph1.TextContent.Add(new SimpleText(Document, Convert.ToString(paragraphId)));
                    table.Rows[currentRow].Cells[0].Content.Add(columnParagraph1);
                    Paragraph columnParagraph2 = ParagraphBuilder.CreateStandardTextParagraph(Document);
                    columnParagraph2.TextContent.Add(new SimpleText(Document, row[Indexes[0]].ToString()));
                    table.Rows[currentRow].Cells[1].Content.Add(columnParagraph2);
                    Paragraph columnParagraph3 = ParagraphBuilder.CreateStandardTextParagraph(Document);
                    columnParagraph3.TextContent.Add(new SimpleText(Document, row[Indexes[1]].ToString()));
                    table.Rows[currentRow].Cells[2].Content.Add(columnParagraph3);
                    Paragraph columnParagraph4 = ParagraphBuilder.CreateStandardTextParagraph(Document);
                    columnParagraph4.TextContent.Add(new SimpleText(Document, row[Indexes[2]].ToString()));
                    table.Rows[currentRow].Cells[3].Content.Add(columnParagraph4);

                    currentRow++;
                    paragraphId++;
                }

                Paragraph result = ParagraphBuilder.CreateStandardTextParagraph(Document);
                result.TextContent.Add(new SimpleText(Document, "Итого по §54:"));
                table.Rows[currentRow].Cells[0].Content.Add(result);
                Paragraph sum = ParagraphBuilder.CreateStandardTextParagraph(Document);
                sum.TextContent.Add(new SimpleText(Document, Fund[2].ToString()));
                table.Rows[currentRow].Cells[3].Content.Add(sum);

                // Сохраняем xml код ячеек которые будут объеднены,
                // чтобы удалить оставшуюся информацию после объединения

                xmlCell1 = table.Rows[currentRow].Cells[1].Node.OuterXml;
                xmlCell2 = table.Rows[currentRow].Cells[2].Node.OuterXml;

                // объединение ячеек
                table.Rows[currentRow].MergeCells(Document, 0, 3, true);

                // Удаление остаточных данных
                innerXml = table.Rows[currentRow].Node.InnerXml;
                innerXml = innerXml.Replace(xmlCell1, "");
                innerXml = innerXml.Replace(xmlCell2, "");

                // Перемещаем метку объедененной ячейки
                innerXml = innerXml.Replace("<table:covered-table-cell xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" />", "");
                String mergedCellXml = table.Rows[currentRow].Cells[0].Node.OuterXml;
                innerXml = innerXml.Replace(mergedCellXml, mergedCellXml +
                                            "<table:covered-table-cell xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" />");
                table.Rows[currentRow].Node.InnerXml = innerXml;

                currentRow++;
            }

            Double totalFund = Fund[0] + Fund[1] + Fund[2];

            Paragraph total = ParagraphBuilder.CreateStandardTextParagraph(Document);

            total.TextContent.Add(new SimpleText(Document, "Итого:"));
            table.Rows[currentRow].Cells[0].Content.Add(total);
            Paragraph totalSum = ParagraphBuilder.CreateStandardTextParagraph(Document);

            totalSum.TextContent.Add(new SimpleText(Document, totalFund.ToString()));
            table.Rows[currentRow].Cells[3].Content.Add(totalSum);

            // Сохраняем xml код ячеек которые будут объеднены,
            // чтобы удалить оставшуюся информацию после объединения

            String finalXmlCell1 = table.Rows[currentRow].Cells[1].Node.OuterXml;
            String finalXmlCell2 = table.Rows[currentRow].Cells[2].Node.OuterXml;

            // объединение ячеек
            table.Rows[currentRow].MergeCells(Document, 0, 3, true);

            // Удаление остаточных данных
            String finalInnerXml = table.Rows[currentRow].Node.InnerXml;

            finalInnerXml = finalInnerXml.Replace(finalXmlCell1, "");
            finalInnerXml = finalInnerXml.Replace(finalXmlCell2, "");

            // Перемещаем метку объедененной ячейки
            finalInnerXml = finalInnerXml.Replace("<table:covered-table-cell xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" />", "");
            String mergedFinalCellXml = table.Rows[currentRow].Cells[0].Node.OuterXml;

            finalInnerXml = finalInnerXml.Replace(mergedFinalCellXml, mergedFinalCellXml +
                                                  "<table:covered-table-cell xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" />");
            table.Rows[currentRow].Node.InnerXml = finalInnerXml;

            Document.Content.Insert(tableId, table);

            if (type != 3)
            {
                Document.SaveTo(filepath);
            }
            else
            {
                BaseFont             baseFont = BaseFont.CreateFont(@"template\\TimesNewRoman.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Font font     = new iTextSharp.text.Font(baseFont, 14);

                DefaultDocumentStyles defaultDocumentStyle;
                if (Document is AODL.Document.TextDocuments.TextDocument)
                {
                    defaultDocumentStyle = DefaultDocumentStyles.Instance(
                        ((AODL.Document.TextDocuments.TextDocument)Document).DocumentStyles, Document);
                }
                else
                {
                    throw new Exception("Unknown IDocument implementation.");
                }

                defaultDocumentStyle.Init();
                defaultDocumentStyle.DefaultTextFont = font;

                var       doc       = new iTextSharp.text.Document();
                PdfWriter pdfWriter = PdfWriter.GetInstance(doc, new FileStream(filepath, FileMode.Create));
                doc.Open();

                ArrayList al = MixedContentConverter.GetMixedPdfContent(Document.Content);

                foreach (Object obj in al)
                {
                    iTextSharp.text.IElement element = obj as iTextSharp.text.IElement;
                    doc.Add(element);
                }

                doc.Close();
            }

            if (Copy)
            {
                Directory.CreateDirectory("ReportsCopy");

                String name = "ReportsCopy//";
                name += DateTime.Now.ToString("g");
                name  = name.Replace(".", "");
                name  = name.Replace(" ", "");
                name  = name.Replace(":", "");
                name += ".odt";

                Document.SaveTo(name);
            }
        }
Ejemplo n.º 24
0
        public void NewTextAndParagraphProps()
        {
            //Create a new TextDocument
            TextDocument document = new TextDocument();

            document.New();
            //Create new Paragraph
            Paragraph paragraph = new Paragraph(document, "P1");

            //Create paragraph border
            ((ParagraphStyle)paragraph.Style).Properties.Border =
                Border.MiddleSolid;
            //Set line spacing to double
            ((ParagraphStyle)paragraph.Style).Properties.LineSpacing =
                ParagraphHelper.LineDouble;
            //Create some formated text
            FormatedText ftext = new FormatedText(paragraph, "T1", @"Outline\n");

            //Set text as Outline
            ((TextStyle)ftext.Style).Properties.Outline = "true";
            //Add to paragraph
            paragraph.TextContent.Add(ftext);
            //Create some formated text
            ftext = new FormatedText(paragraph, "T2", @"Colored\n");
            //Set font color
            ((TextStyle)ftext.Style).Properties.FontColor = Colors.GetColor(System.Drawing.Color.Cyan);
            //Add to paragraph
            paragraph.TextContent.Add(ftext);
            //Create some formated text
            ftext = new FormatedText(paragraph, "T3", @"Backcolor\n");
            //Set background color
            ((TextStyle)ftext.Style).Properties.BackgroundColor = Colors.GetColor(System.Drawing.Color.Cyan);
            //Add to paragraph
            paragraph.TextContent.Add(ftext);
            //Create some formated text
            ftext = new FormatedText(paragraph, "T4", @"Shadow\n");
            //Set shadow
            ((TextStyle)ftext.Style).Properties.Shadow = TextPropertieHelper.Shadowmidlle;
            //Add to paragraph
            paragraph.TextContent.Add(ftext);
            //Create some formated text
            ftext = new FormatedText(paragraph, "T5", @"Subscript\n");
            //Set subscript
            ((TextStyle)ftext.Style).Properties.Position = TextPropertieHelper.Subscript;
            //Add to paragraph
            paragraph.TextContent.Add(ftext);
            //Create some formated text
            ftext = new FormatedText(paragraph, "T6", @"Superscript\n");
            //Set superscript
            ((TextStyle)ftext.Style).Properties.Position = TextPropertieHelper.Superscript;
            //Add to paragraph
            paragraph.TextContent.Add(ftext);
            //Create some formated text
            ftext = new FormatedText(paragraph, "T7", @"Strice through\n");
            //Set superscript
            ((TextStyle)ftext.Style).Properties.TextLineThrough = LineStyles.solid;
            //Add to paragraph
            paragraph.TextContent.Add(ftext);
            //finally add paragraph to the document
            document.Content.Add(paragraph);
            //Save the document
            document.SaveTo("NewProperties.odt");
        }
Ejemplo n.º 25
0
        private void PrintDeposantList()
        {
            var deposantList = m_databaseInterface.GetDeposantList();

            TextDocument document = new TextDocument();

            document.New();
            Paragraph    paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
            FormatedText formText  = new FormatedText(document, "T1", "Liste des déposants");

            formText.TextStyle.TextProperties.Bold = "bold";
            paragraph.TextContent.Add(formText);
            //Add the paragraph to the document
            document.Content.Add(paragraph);
            //Save
            // Get the Word application object.
            //   Word._Application word_app = new Word.Application();

            // Make Word visible (optional).
            //   word_app.Visible = true;

            // Create the Word document.
            //   object missing = Type.Missing;
            //   object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
            //   Word._Document word_doc = word_app.Documents.Add(
            //       ref missing, ref missing, ref missing, ref missing);

            // Create a header paragraph.
            // Word.Paragraph para = word_doc.Paragraphs.Add(ref missing);
            //object style_name = "Title";
            //para.Range.set_Style(ref style_name);
            //para.Range.InsertParagraphAfter();
            //para.Range.Text = "Liste des déposants"

            //Insert a 3 x 5 table, fill it with data, and make the first row
            //bold and italic.

            Table table = TableBuilder.CreateTextDocumentTable(
                document,
                "table1",
                "table1",
                deposantList.Count + 1,
                2,
                16.99,
                true,
                true);
            int r;

            for (r = 0; r < deposantList.Count; r++)
            {
                //Create a standard paragraph
                Paragraph paragraph1 = ParagraphBuilder.CreateStandardTextParagraph(document);
                //Add some simple text
                paragraph1.TextContent.Add(new SimpleText(document, deposantList[r].Nom));
                //Insert paragraph into the first cell
                table.RowCollection[r].CellCollection[0].Content.Add(paragraph1);
            }

            //Add table to the document
            document.Content.Add(table);
            document.SaveTo("C:/foireVelo/test.odt");
            System.Diagnostics.Process.Start("C:/foireVelo/test.odt");
            //Word.Table oTable;
            //Word.Range wrdRng = word_doc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            //oTable = word_doc.Tables.Add(wrdRng, deposantList.Count+1, 2, ref missing, ref missing);
            //oTable.Range.ParagraphFormat.SpaceAfter = 6;
            //int r;
            //string strText;
            ////oTable.Cell(0, 0).Range.Text = "Nom";
            ////oTable.Cell(0, 1).Range.Text = "Signature";
            //for (r = 0; r < deposantList.Count; r++)
            //{
            //    strText = deposantList[r].Nom;
            //    oTable.Cell(r+1, 0).Range.Text = strText;
            //}

            //oTable.Columns[1].Width = 200;
            //oTable.Borders.Enable = 1;
        }
Ejemplo n.º 26
0
		public void ParagraphContentTest()
		{
			TextDocument td		= new TextDocument();
			td.New();

			Paragraph p			= new Paragraph(td, "P1");
			((ParagraphStyle)p.Style).Properties.Alignment = TextAlignments.end.ToString();
			//Add some content
			p.TextContent.Add( new SimpleText((IContent)p, "Hallo i'm simple text!"));
			Assert.IsTrue(p.TextContent.Count > 0, "Must be greater than zero!");
			FormatedText ft = new FormatedText((IContent)p, "T1", " \"And < > &     i'm formated text!");
			((TextStyle)ft.Style).Properties.Bold = "bold";
			((TextStyle)ft.Style).Properties.Italic = "italic";
			((TextStyle)ft.Style).Properties.SetUnderlineStyles( 
				LineStyles.wave, LineWidths.bold.ToString(), "#A1B1C2");
//			((TextStyle)ft.Style).Properties.Underline = LineStyles.dotted;
//			((TextStyle)ft.Style).Properties.UnderlineColor = "font-color";
//			((TextStyle)ft.Style).Properties.UnderlineWidth = LineWidths.auto.ToString();
			p.TextContent.Add(ft);			
			Assert.IsTrue(p.TextContent.Count == 2, "Must be two!");
			//Add as document content 
			td.Content.Add(p);
			//Console.WriteLine(td.XmlDoc.OuterXml);
			//Generate and save
			td.SaveTo("ParagraphTest.odt");
		}
Ejemplo n.º 27
0
		public void FooterAndHeader()
		{
			//Create a new document
			TextDocument td		= new TextDocument();
			td.New();
			//Create a new paragraph
			Paragraph p			= new Paragraph(td, "P1");
			//Create some formated text
			FormatedText ftext	= new FormatedText(p, "F1", "Im the Header");
			((TextStyle)ftext.Style).Properties.Italic = "italic";
			//add the text
			p.TextContent.Add(ftext);
			//Insert paragraph as header
			td.InsertHeader(p);
			//New paragraph 
			p					= new Paragraph(td, ParentStyles.Standard,
				"I'm the Footer");
			//Insert paragraph as footer
			td.InsertFooter(p);
			//Save
			td.SaveTo("Header_Footer.odt");
		}
Ejemplo n.º 28
0
		public void NewTextAndParagraphProps()
		{
			//Create a new TextDocument
			TextDocument document		= new TextDocument();
			document.New();
			//Create new Paragraph
			Paragraph paragraph			= new Paragraph(document, "P1");
			//Create paragraph border
			((ParagraphStyle)paragraph.Style).Properties.Border =
				Border.MiddleSolid;
			//Set line spacing to double
			((ParagraphStyle)paragraph.Style).Properties.LineSpacing =
				ParagraphHelper.LineDouble;
			//Create some formated text
			FormatedText ftext			= new FormatedText(paragraph, "T1", @"Outline\n");
			//Set text as Outline
			((TextStyle)ftext.Style).Properties.Outline		= "true";
			//Add to paragraph
			paragraph.TextContent.Add(ftext);
			//Create some formated text
			ftext						= new FormatedText(paragraph, "T2", @"Colored\n");
			//Set font color
			((TextStyle)ftext.Style).Properties.FontColor	= Colors.GetColor(System.Drawing.Color.Cyan);
			//Add to paragraph
			paragraph.TextContent.Add(ftext);
			//Create some formated text
			ftext						= new FormatedText(paragraph, "T3", @"Backcolor\n");
			//Set background color
			((TextStyle)ftext.Style).Properties.BackgroundColor	= Colors.GetColor(System.Drawing.Color.Cyan);
			//Add to paragraph
			paragraph.TextContent.Add(ftext);
			//Create some formated text
			ftext						= new FormatedText(paragraph, "T4", @"Shadow\n");
			//Set shadow
			((TextStyle)ftext.Style).Properties.Shadow		= TextPropertieHelper.Shadowmidlle;
			//Add to paragraph
			paragraph.TextContent.Add(ftext);
			//Create some formated text
			ftext						= new FormatedText(paragraph, "T5", @"Subscript\n");
			//Set subscript
			((TextStyle)ftext.Style).Properties.Position	= TextPropertieHelper.Subscript;
			//Add to paragraph
			paragraph.TextContent.Add(ftext);
			//Create some formated text
			ftext						= new FormatedText(paragraph, "T6", @"Superscript\n");
			//Set superscript
			((TextStyle)ftext.Style).Properties.Position	= TextPropertieHelper.Superscript;
			//Add to paragraph
			paragraph.TextContent.Add(ftext);
			//Create some formated text
			ftext						= new FormatedText(paragraph, "T7", @"Strice through\n");
			//Set superscript
			((TextStyle)ftext.Style).Properties.TextLineThrough = LineStyles.solid;
			//Add to paragraph
			paragraph.TextContent.Add(ftext);
			//finally add paragraph to the document
			document.Content.Add(paragraph);
			//Save the document
			document.SaveTo("NewProperties.odt");
		}