Ejemplo n.º 1
0
        public void SerializeWorksheetDocumentTest()
        {
            CT_Worksheet worksheet = new CT_Worksheet();
            worksheet.dimension = new CT_SheetDimension();
            worksheet.dimension.@ref = "A1:C1";

            var sheetData = worksheet.AddNewSheetData();
            var row = sheetData.AddNewRow();
            row.r = 1u;
            row.spans = "1:3";
            {
                var c = row.AddNewC();
                c.r = "A1";
                c.t = ST_CellType.s;
                c.v = "0";
            }
            {
                var c = row.AddNewC();
                c.r = "B1";
                c.t = ST_CellType.s;
                c.v = "1";
            }
            {
                var c = row.AddNewC();
                c.r = "C1";
                c.t = ST_CellType.s;
                c.v = "8";
            }
            var hyper = worksheet.AddNewHyperlinks();
            var link = new CT_Hyperlink();
            link.@ref="B1";
            link.id="rId1";
            hyper.hyperlink.Add(link);
            StringWriter stream = new StringWriter();
            WorksheetDocument_Accessor.serializer.Serialize(stream, worksheet, WorksheetDocument_Accessor.namespaces);
            string expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
            <worksheet xmlns:r=""http://schemas.openxmlformats.org/officeDocument/2006/relationships"" xmlns=""http://schemas.openxmlformats.org/spreadsheetml/2006/main"">
              <dimension ref=""A1:C1"" />
              <sheetData>
            <row r=""1"" spans=""1:3"">
              <c r=""A1"" t=""s"">
            <v>0</v>
              </c>
              <c r=""B1"" t=""s"">
            <v>1</v>
              </c>
              <c r=""C1"" t=""s"">
            <v>8</v>
              </c>
            </row>
              </sheetData>
              <hyperlinks>
            <hyperlink ref=""B1"" r:id=""rId1"" />
              </hyperlinks>
            </worksheet>";
            Assert.AreEqual(expected, stream.ToString());
        }
Ejemplo n.º 2
0
        /**
         * Create a new CT_Worksheet instance with all values set to defaults
         *
         * @return a new instance
         */
        private static CT_Worksheet NewSheet()
        {
            CT_Worksheet worksheet = new CT_Worksheet();
            CT_SheetFormatPr ctFormat = worksheet.AddNewSheetFormatPr();
            ctFormat.defaultRowHeight = (15.0);

            CT_SheetView ctView = worksheet.AddNewSheetViews().AddNewSheetView();
            ctView.workbookViewId = (0);

            worksheet.AddNewDimension().@ref = "A1";

            worksheet.AddNewSheetData();

            CT_PageMargins ctMargins = worksheet.AddNewPageMargins();
            ctMargins.bottom = (0.75);
            ctMargins.footer = (0.3);
            ctMargins.header = (0.3);
            ctMargins.left = (0.7);
            ctMargins.right = (0.7);
            ctMargins.top = (0.75);

            return worksheet;
        }