public override void ExportImpl(Window parentWindow, Data.DataMatrix matrix, string datasetName, object optionsObj)
        {
            ExcelExporterOptions options = optionsObj as ExcelExporterOptions;

            if (options == null)
            {
                return;
            }

            if (FileExistsAndNotOverwrite(options.Filename))
            {
                return;
            }

            ProgressStart("Preparing to export...");

            int totalRows = matrix.Rows.Count;

            using (ExcelPackage p = new ExcelPackage(new FileInfo(options.Filename))) {
                //Here setting some document properties
                var v       = this.GetType().Assembly.GetName().Version;
                var version = String.Format("Version {0}.{1} (build {2})", v.Major, v.Minor, v.Revision);
                p.Workbook.Properties.Author = "BioLink " + version;
                var name = StringUtils.RemoveAll(datasetName, '&', '\'', '"', '<', '>');
                p.Workbook.Properties.Title = name;
                var ws = p.Workbook.Worksheets.Add("DwC");

                // Column headings...
                int colIndex = 1;
                matrix.Columns.ForEach(column => {
                    var cell = ws.Cells[1, colIndex++].Value = column.Name;
                });

                int rowIndex = 0;
                foreach (MatrixRow row in matrix.Rows)
                {
                    for (int i = 0; i < matrix.Columns.Count; ++i)
                    {
                        if (!matrix.Columns[i].IsHidden)
                        {
                            object val      = row[i];
                            String strValue = (val == null ? "" : val.ToString());
                            ws.SetValue(rowIndex + 2, i + 1, strValue);
                        }
                    }
                    if (rowIndex++ % 1000 == 0)
                    {
                        double percent = ((double)rowIndex / (double)totalRows) * 100.0;
                        ProgressMessage(String.Format("Exported {0} of {1} rows...", rowIndex, totalRows), percent);
                    }
                }

                ProgressMessage(String.Format("Exported {0} of {1} rows. Saving file '{2}'", rowIndex, totalRows, options.Filename), 100);

                p.Save();
            }

            ProgressEnd(String.Format("{0} rows exported.", totalRows));
        }
        public override void ExportImpl(Window parentWindow, Data.DataMatrix matrix, string datasetName, object optionsObj)
        {
            ExcelExporterOptions options = optionsObj as ExcelExporterOptions;

            if (options == null)
            {
                return;
            }

            if (FileExistsAndNotOverwrite(options.Filename))
            {
                return;
            }

            ProgressStart("Preparing to export...");

            int totalRows = matrix.Rows.Count;

            using (StreamWriter writer = new StreamWriter(options.Filename)) {
                writer.WriteLine("<?xml version=\"1.0\"?><ss:Workbook xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\">");
                writer.WriteLine("<ss:Worksheet ss:Name=\"" + datasetName + "\">");
                writer.WriteLine("<ss:Table>");
                int currentRow = 0;
                foreach (MatrixRow row in matrix.Rows)
                {
                    writer.WriteLine("<ss:Row>");
                    for (int i = 0; i < matrix.Columns.Count; ++i)
                    {
                        if (!matrix.Columns[i].IsHidden)
                        {
                            object val = row[i];
                            writer.Write("<ss:Cell><ss:Data ss:Type=\"String\">");
                            String str = (val == null ? "" : val.ToString());
                            writer.Write(Escape(str));
                            writer.Write("</ss:Data></ss:Cell>");
                        }
                    }
                    if (++currentRow % 1000 == 0)
                    {
                        double percent = ((double)currentRow / (double)totalRows) * 100.0;
                        ProgressMessage(String.Format("Exported {0} of {1} rows...", currentRow, totalRows), percent);
                    }

                    writer.WriteLine("</ss:Row>");
                }

                writer.WriteLine("</ss:Table>");
                writer.WriteLine("</ss:Worksheet>");
                writer.WriteLine("</ss:Workbook>");
            }

            ProgressEnd(String.Format("{0} rows exported.", totalRows));
        }
        protected override object GetOptions(Window parentWindow, DataMatrix matrix, String datasetName)
        {
            string filename = PromptForFilename(".sqlite", "SQLite database (.sqlite)|*.sqlite", datasetName);

            if (!String.IsNullOrEmpty(filename))
            {
                ExcelExporterOptions options = new ExcelExporterOptions();
                options.Filename = filename;
                return(options);
            }

            return(null);
        }
        protected override object GetOptions(Window parentWindow, DataMatrix matrix, String datasetName)
        {
            var filename = PromptForFilename(".txt", "XML Excel Workbook (.xml)|*.xml");

            if (!String.IsNullOrEmpty(filename))
            {
                ExcelExporterOptions options = new ExcelExporterOptions();
                options.Filename = filename;
                return(options);
            }

            return(null);
        }
        public override void ExportImpl(Window parentWindow, Data.DataMatrix matrix, string datasetName, object optionsObj)
        {
            ExcelExporterOptions options = optionsObj as ExcelExporterOptions;

            if (options == null)
            {
                return;
            }

            ProgressStart("Exporting...");

            int totalRows = matrix.Rows.Count;

            if (FileExistsAndNotOverwrite(options.Filename))
            {
                return;
            }
            FileInfo file = new FileInfo(options.Filename);

            using (SQLiteExporterService service = new SQLiteExporterService(file.FullName)) {
                service.CreateTable("ExportedData", matrix);

                service.BeginTransaction();
                int count = 0;
                foreach (MatrixRow row in matrix)
                {
                    service.InsertRow("ExportedData", row);
                    if (++count % 1000 == 0)
                    {
                        double percent = ((double)count / (double)totalRows) * 100.0;
                        ProgressMessage(String.Format("Exporting {0} rows of {1}...", count, totalRows), percent);
                    }
                }
                ProgressMessage(String.Format("Saving...", count, totalRows));
                service.CommitTransaction();
            }

            ProgressEnd(String.Format("{0} rows exported.", totalRows));
        }
Example #6
0
        protected override object GetOptions(Window parentWindow, DataMatrix matrix, String datasetName)
        {
            string filename = PromptForFilename(".sqlite", "SQLite database (.sqlite)|*.sqlite", datasetName);
            if (!String.IsNullOrEmpty(filename)) {
                ExcelExporterOptions options = new ExcelExporterOptions();
                options.Filename = filename;
                return options;
            }

            return null;
        }
Example #7
0
        protected override object GetOptions(Window parentWindow, DataMatrix matrix, String datasetName)
        {
            var filename = PromptForFilename(".txt", "Excel 2007/2010 Workbook (.xlsx)|*.xlsx", datasetName);
            if (!String.IsNullOrEmpty(filename)) {
                ExcelExporterOptions options = new ExcelExporterOptions();
                options.Filename = filename;
                return options;
            }

            return null;
        }