Beispiel #1
0
        private void saveToFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataTable table = this.DataTable;

            if (table != null)
            {
                if (resultSaveFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    string ext = Path.GetExtension(resultSaveFileDialog.FileName).ToLower();
                    if (ext == ".txt" || ext == ".csv")
                    {
                        char separator = (ext == ".txt") ? '\t' : ',';
                        DataUtils.WriteToFile(resultSaveFileDialog.FileName, table, separator);
                    }
                    else if (ext == ".xml")
                    {
                        if (String.IsNullOrEmpty(table.TableName))
                        {
                            table.TableName = Path.GetFileNameWithoutExtension(resultSaveFileDialog.FileName);
                        }
                        table.WriteXml(resultSaveFileDialog.FileName);
                    }
                    else
                    {
                        using (var reader = table.CreateDataReader()) {
                            Xlsx.Save(resultSaveFileDialog.FileName, "Result", reader);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        private void executeToXlsxWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var args = (ExecuteToXlsxArgs)e.Argument;

            using (var command = args.Command) {
                using (var reader = command.ExecuteReader()) {
                    Xlsx.Save(args.FileName, "Result", reader);
                }
            }
        }