コード例 #1
0
        /// <summary>
        /// Saves the given DataTable to the given Excel path and file name
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="saveAsPathAndFile"></param>
        /// <param name="openAfterSave"></param>
        public static void ExportDataTableToExcel(DataTable dt, string saveAsPathAndFile, bool openAfterSave)
        {
            if (String.IsNullOrEmpty(saveAsPathAndFile))
            {
                throw new Exception("Missing saveAsPathAndFile for ExportDataSetToExcel()!");
            }

            Spire.DataExport.XLS.CellExport cellExport = new Spire.DataExport.XLS.CellExport();
            cellExport.Register(RegAcctNm, RegAcctKey);

            Spire.DataExport.XLS.WorkSheet worksheet1 = new Spire.DataExport.XLS.WorkSheet();

            worksheet1.DataSource      = Spire.DataExport.Common.ExportSource.DataTable;
            worksheet1.DataTable       = dt;
            worksheet1.StartDataCol    = ((System.Byte)(0));
            worksheet1.AutoFitColWidth = true;
            cellExport.Sheets.Add(worksheet1);

            if (openAfterSave)
            {
                cellExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
            }

            cellExport.SaveToFile(saveAsPathAndFile);

            Console.WriteLine(saveAsPathAndFile + " was created.");
        }
コード例 #2
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (textBox2.Text == "")
     {
         MessageBox.Show("Filename Field Empty", "warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     else
     {
         string fileName;
         Spire.DataExport.XLS.CellExport cellExport = new Spire.DataExport.XLS.CellExport();
         Spire.DataExport.XLS.WorkSheet  worksheet1 = new Spire.DataExport.XLS.WorkSheet();
         worksheet1.DataSource   = Spire.DataExport.Common.ExportSource.DataTable;
         worksheet1.DataTable    = this.dataGridView1.DataSource as DataTable;
         worksheet1.StartDataCol = ((System.Byte)(0));
         cellExport.Sheets.Add(worksheet1);
         cellExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
         fileName = textBox2.Text.ToString() + ".xls";
         cellExport.SaveToFile(fileName);
     }
 }
コード例 #3
0
        private void btnRun_Click(object sender, System.EventArgs e)
        {
            oleDbConnection1.Open();
            try
            {
                switch (itemIndex)
                {
                case 1:
                    cellExport1.SaveToFile();
                    break;

                case 2:
                    htmlExport1.SaveToFile();
                    break;

                case 3:
                    pdfExport1.SaveToFile();
                    break;

                case 4:
                    rtfExport1.SaveToFile();
                    break;

                case 5:
                    clipboardExport1.SaveToFile();
                    break;

                case 6:
                    dbfExport1.SaveToFile();
                    break;

                case 7:
                    accessExport1.SaveToFile();
                    break;

                case 8:
                    xmlExport1.SaveToFile();
                    break;

                case 9:
                    sqlExport1.SaveToFile();
                    break;

                case 10:
                    txtExport1.ExportType = TextExportType.SYLK;
                    txtExport1.FileName   = "sample.slk";
                    txtExport1.SaveToFile();
                    break;

                case 11:
                    txtExport1.ExportType = TextExportType.CSV;
                    txtExport1.FileName   = "sample.csv";
                    txtExport1.SaveToFile();
                    break;

                case 12:
                    txtExport1.ExportType = TextExportType.DIF;
                    txtExport1.FileName   = "sample.dif";
                    txtExport1.SaveToFile();
                    break;

                case 13:
                    txtExport1.ExportType = TextExportType.TXT;
                    txtExport1.FileName   = "sample.txt";
                    txtExport1.SaveToFile();
                    break;
                }
            }finally
            {
                this.oleDbConnection1.Close();
            }
        }