Exemplo n.º 1
0
Arquivo: Form1.cs Projeto: MTigra/KDZ2
        /// <summary>
        /// Сохранение в файл
        /// </summary>
        private void сохранитьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string path = saveFileDialog1.FileName;
                var    aa   = new ClosedXML.Excel.XLWorkbook();

                var ws = aa.AddWorksheet(ToDataTable(dataGridView1), "name");
                ws.Tables.First().ShowAutoFilter = false;
                ws.Tables.First().Theme          = XLTableTheme.None;
                ws.Style = XLWorkbook.DefaultStyle;
                aa.SaveAs(path);
                MessageBox.Show("Файл сохранен.");
            }
        }
Exemplo n.º 2
0
        private static void ExportDataSet(DataSet ds)
        {
            var workbook = new ClosedXML.Excel.XLWorkbook();
            foreach (DataTable dt in ds.Tables)
            {
                var worksheet = workbook.Worksheets.Add(dt.TableName);
                worksheet.Cell(1, 1).InsertTable(dt);
                worksheet.Columns().AdjustToContents();
            }

            SaveFileDialog sFD = new SaveFileDialog();
            sFD.Filter = "Excel file (.xlsx)|*.xlsx";
            if (sFD.ShowDialog() == true)
            {
                workbook.SaveAs(sFD.FileName);
                workbook.Dispose();
            }
        }
Exemplo n.º 3
0
        private static void ExportDataSet(DataSet ds)
        {
            var workbook = new ClosedXML.Excel.XLWorkbook();

            foreach (DataTable dt in ds.Tables)
            {
                var worksheet = workbook.Worksheets.Add(dt.TableName);
                worksheet.Cell(1, 1).InsertTable(dt);
                worksheet.Columns().AdjustToContents();
            }

            SaveFileDialog sFD = new SaveFileDialog();

            sFD.Filter = "Excel file (.xlsx)|*.xlsx";
            if (sFD.ShowDialog() == true)
            {
                workbook.SaveAs(sFD.FileName);
                workbook.Dispose();
            }
        }