Ejemplo n.º 1
0
        public static void ToExcelXML(IEnumerable <DataSource> datasources, string filename, bool write_column_headers)
        {
            if (datasources == null)
            {
                throw new System.ArgumentNullException("datasources");
            }

            var writer = new Formats.ExcelXMLWriter(filename);

            writer.StartDocument();
            writer.StartWorkBook();
            foreach (var datasource in datasources)
            {
                string sheetname = datasource.Name;

                if (string.IsNullOrEmpty(sheetname))
                {
                    string msg = string.Format("Datasource contains a null or blank Name for a worksheet");
                }
                write_worksheet(datasource, writer, sheetname, write_column_headers);
            }
            writer.EndWorkBook();
            writer.EndDocument();
            writer.Close();
        }
Ejemplo n.º 2
0
        private static void write_worksheet(DataSource datasource, Formats.ExcelXMLWriter writer, string sheetname, bool write_column_headers)
        {
            var schema    = datasource.GetSchema();
            int num_cols  = schema.Fields.Count;
            var datatypes = Enumerable.Repeat(Formats.ExcelXMLWriter.DataType.String, num_cols).ToArray();

            for (int i = 0; i < num_cols; i++)
            {
                var col = schema.Fields[i];
                if (col.Type == typeof(System.DateTime))
                {
                    datatypes[i] = Formats.ExcelXMLWriter.DataType.DateTime;
                }
            }

            writer.StartWorkSheet(sheetname, num_cols, datatypes);

            if (write_column_headers)
            {
                writer.StartRow();
                foreach (var col in schema.Fields)
                {
                    var cn  = col.Name;
                    var cdt = Formats.ExcelXMLWriter.DataType.String;
                    writer.Cell(cn, cdt);
                }

                writer.EndRow();
            }

            var excel_datatypes = schema.Fields.AsEnumerable().Select(col => DataUtil.getdt(col.Type)).ToList();

            foreach (var row in datasource.Rows)
            {
                writer.StartRow();
                for (int i = 0; i < row.ItemArray.Length; i++)
                {
                    var datatable_col = schema.Fields[i];
                    var excel_dt      = excel_datatypes[i];
                    var item          = row.ItemArray[i];

                    string cell_str = Isotope.Data.DataUtil.DataTableToExcelXML_get_cellstr(item, excel_dt, datatable_col);

                    writer.Cell(cell_str, excel_dt);
                }

                writer.EndRow();
            }

            writer.EndWorkSheet();
        }
Ejemplo n.º 3
0
        public static void ToExcelXML(IEnumerable<DataSource> datasources, string filename, bool write_column_headers)
        {
            if (datasources == null)
            {
                throw new System.ArgumentNullException("datasources");
            }

            var writer = new Formats.ExcelXMLWriter(filename);
            writer.StartDocument();
            writer.StartWorkBook();
            foreach (var datasource in datasources)
            {
                string sheetname = datasource.Name;

                if (string.IsNullOrEmpty(sheetname))
                {
                    string msg = string.Format("Datasource contains a null or blank Name for a worksheet");
                }
                write_worksheet(datasource, writer, sheetname, write_column_headers);
            }
            writer.EndWorkBook();
            writer.EndDocument();
            writer.Close();
        }