Example #1
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));
            }
        }
Example #2
0
 /// <summary>
 /// Gets the width of the content.
 /// </summary>
 /// <value>The width of the content area as double value without the left and right margins.
 /// Notice, that you have to call GetLayoutMeasurement() to find out if
 /// the the document use cm or inch.</value>
 /// <remarks>Will return 0 if the width couldn't be calculated.</remarks>
 public double GetContentWidth()
 {
     if (PageWidth != null &&
         SizeConverter.GetDoubleFromAnOfficeSizeValue(PageWidth) > 0)
     {
         return(SizeConverter.GetDoubleFromAnOfficeSizeValue(PageWidth)
                - SizeConverter.GetDoubleFromAnOfficeSizeValue(MarginLeft)
                - SizeConverter.GetDoubleFromAnOfficeSizeValue(MarginRight));
     }
     return(0);
 }
Example #3
0
 /// <summary>
 /// Gets the width of the content.
 /// </summary>
 /// <value>The width of the content area as double value without the left and right margins.
 /// Notice, that you have to call GetLayoutMeasurement() to find out if
 /// the the document use cm or inch.</value>
 /// <remarks>Will return 0 if the width couldn't be calculated.</remarks>
 public double GetContentWidth()
 {
     try
     {
         if (this.PageWidth != null &&
             SizeConverter.GetDoubleFromAnOfficeSizeValue(this.PageWidth) > 0)
         {
             return(SizeConverter.GetDoubleFromAnOfficeSizeValue(this.PageWidth)
                    - SizeConverter.GetDoubleFromAnOfficeSizeValue(this.MarginLeft)
                    - SizeConverter.GetDoubleFromAnOfficeSizeValue(this.MarginRight));
         }
         return(0);
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #4
0
 private static double ConvertToCM(string width)
 {
     try
     {
         bool             isInch       = SizeConverter.IsInch(width);
         NumberFormatInfo numberFormat = CultureInfo.InvariantCulture.NumberFormat;
         width = width.Replace(",", ".");
         double w = SizeConverter.GetDoubleFromAnOfficeSizeValue(width);
         if (isInch)
         {
             w = SizeConverter.InchToCm(w);
         }
         return(w);
     }
     catch (FormatException e)
     {
         throw new ContentMockerException(string.Format(
                                              "Failed to convert {0} into decimal value", width), e);
     }
 }