Пример #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());
        }