Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="values"></param>
        public void WriteRow(object[] values)
        {
            Assert.IsNotNull(values);

            WriteStartRow();

            for (var columnIndex = 0; columnIndex < values.Length; columnIndex++)
            {
                var value = values[columnIndex];
                XmlSpreadsheetDataType type;
                string xmlValue;

                if (value == DBNull.Value)
                {
                    xmlValue = null;
                    type     = XmlSpreadsheetDataType.String;
                }
                else
                {
                    var column = _table.Columns[columnIndex];
                    type     = column.DataType;
                    xmlValue = column.Convert(value);
                }

                var cell = new XmlSpreadsheetCell(type, xmlValue);
                cell.StyleId = $"{_tableIndex},{columnIndex}";
                cell.Write(XmlWriter);
            }

            WriteEndRow();
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="table"></param>
        public void WriteStartTable(XmlSpreadsheetTable table)
        {
            Assert.IsNotNull(table);
            _tableIndex++;
            _table = table;

            XmlWriter.WriteStartElement("Worksheet");
            XmlWriter.WriteAttributeString("ss:Name", _table.TableName);

            XmlWriter.WriteStartElement("Table");

            var columnIndex = 1;

            foreach (var column in _table.Columns)
            {
                using (XmlWriter.WriteElement("Column"))
                {
                    XmlWriter.WriteAttributeString("ss:Index", columnIndex.ToString());

                    if (column.Width != null)
                    {
                        XmlWriter.WriteAttributeString("ss:Width", column.Width);
                    }
                }

                columnIndex++;
            }

            using (XmlWriter.WriteElement("Row"))
            {
                foreach (var column in _table.Columns)
                {
                    var cell =
                        new XmlSpreadsheetCell(XmlSpreadsheetDataType.String, column.ColumnName)
                    {
                        StyleId = "ColumnHeader"
                    };
                    cell.Write(XmlWriter);
                }
            }
        }