コード例 #1
0
        public ActionResult ExportExcel()
        {
            var obj = new ExportDataTable();

            var dt = (DataTable)TempData["DataTable"];

            var stream = obj.ExportExcel(dt);

            return(File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "MismatchedResult.xlsx"));
        }
コード例 #2
0
        private void btnExportar_Click(object sender, EventArgs e)
        {
            ExportDataTable exDt = new ExportDataTable();

            exDt.Table = prods.Table;

            exDt.TagRoot            = "Produtos";
            exDt.TagRow             = "Produto";
            exDt.CsvWithCollumNames = true;

            // se for para XML
            if (rbXMLAtributos.Checked || rbXMLElementos.Checked)
            {
                // configurar a janela de salvar para XML
                dlsSalvar.FileName   = "Produtos.xml";
                dlsSalvar.Filter     = "Arquivos xml|*.xml|Todos os arquivos|*.*";
                dlsSalvar.DefaultExt = "xml";
                // se não confirmar o salvamento
                if (dlsSalvar.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }

                // NOVO
                exDt.FileName = dlsSalvar.FileName;
                if (rbXMLAtributos.Checked)
                {
                    exDt.ExportToXMLAttributes();
                }
                else
                {
                    exDt.ExportToXMLElements();
                }
            }
            else // CSV
            {
                // configurar a janela de salvar para XML
                dlsSalvar.FileName   = "Produtos.csv";
                dlsSalvar.Filter     = "Arquivos csv|*.csv|Todos os arquivos|*.*";
                dlsSalvar.DefaultExt = "csv";
                // se não confirmar o salvamento
                if (dlsSalvar.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }

                // NOVO
                exDt.FileName = dlsSalvar.FileName;
                exDt.ExportToCSV();
            }
            // using System.Diagnostics
            // mostra o arquivo dentro do seu aplicativo padrão
            Process.Start(dlsSalvar.FileName);
        }
コード例 #3
0
 static void Main(string[] args)
 {
     DataTable dt = ElectronicsDataTable.GetData();
     var exp = new ExportDataTable();
     exp.PathTemplateFolder = Path.Combine(Environment.CurrentDirectory, @"exportsTemplates\electronics");
     exp.ExportTo(dt, ExportToFormat.HTML, "a.html");
     exp.ExportTo(dt, ExportToFormat.CSV, "a.csv");
     exp.ExportTo(dt, ExportToFormat.XML, "a.xml");
     exp.ExportTo(dt, ExportToFormat.Word2003XML, "a_2003.doc");
     exp.ExportTo(dt, ExportToFormat.Excel2003XML, "a_2003.xls");
     exp.ExportTo(dt, ExportToFormat.PDFtextSharpXML, "a.pdf");
     exp.ExportTo(dt, ExportToFormat.Excel2007, "a.xlsx");
     exp.ExportTo(dt, ExportToFormat.Word2007, "a.docx");
     exp.ExportTo(dt, ExportToFormat.itextSharpXML, "a.xml");
 }
コード例 #4
0
        static void Main(string[] args)
        {
            DataTable dt  = ElectronicsDataTable.GetData();
            var       exp = new ExportDataTable();

            exp.PathTemplateFolder = Path.Combine(Environment.CurrentDirectory, @"exportsTemplates\electronics");
            exp.ExportTo(dt, ExportToFormat.HTML, "a.html");
            exp.ExportTo(dt, ExportToFormat.CSV, "a.csv");
            exp.ExportTo(dt, ExportToFormat.XML, "a.xml");
            exp.ExportTo(dt, ExportToFormat.Word2003XML, "a_2003.doc");
            exp.ExportTo(dt, ExportToFormat.Excel2003XML, "a_2003.xls");
            exp.ExportTo(dt, ExportToFormat.PDFtextSharpXML, "a.pdf");
            exp.ExportTo(dt, ExportToFormat.Excel2007, "a.xlsx");
            exp.ExportTo(dt, ExportToFormat.Word2007, "a.docx");
            exp.ExportTo(dt, ExportToFormat.itextSharpXML, "a.xml");
        }
コード例 #5
0
 protected void btnPrint_Click(object sender, EventArgs e)
 {
     ExportDataTable Export = new ExportDataTable();
     DataTable dt = GetDataTable();
     Export.dataTable = dt;
     //不顯示的欄位
     Export.DisableColumn.Add("uid");
     string name = "個案轉介管理";
     string time ="";
     if (txtBegCreateDate.Text != "" && txtEndCreateDate.Text != "")
     {
         time = "("+txtBegCreateDate.Text + "~" + txtEndCreateDate.Text+")";
     }
     string Title = Export.GetTitle(name + time , 3);
     string ExportData = Title + Export.Render();
     Util.OutputTxt(ExportData, "1", "個案轉介管理" + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"));
 }
コード例 #6
0
    //------------------------------------------------------------------------------
    protected void btnPrint_Click(object sender, EventArgs e)
    {
        string 列印模式新增表頭 = "";

        列印模式新增表頭 += "<table><tr><td colspan=\"8\" style=\"font-size:24px;font-family:標楷體;width:100%;\">";
        列印模式新增表頭 += "志工服務紀錄表";
        if (txtsDate.Text.Trim() != "" && txteDate.Text.Trim() != "") {
            列印模式新增表頭 += "(" + txtsDate.Text.Trim() + "∼" + txteDate.Text.Trim() + ")"; 
        }
        列印模式新增表頭 += "統計";
        列印模式新增表頭 += "</td></tr></table>\n";

        //原始的寫法,其實看不懂在寫甚麼
        ExportDataTable Export = new ExportDataTable();
        DataTable dt = GetDataTable("", "");
        Export.dataTable = dt;
        Export.DisableColumn.Add("ColName");
        string ExportData = Title + Export.Render();
        
        string s = @"<head>
                        <style>
                        @page Section2
                        { size:841.7pt 595.45pt;
                          mso-page-orientation:landscape;
                        margin:1.5cm 0.5cm 0.5cm 0.5cm;}
                        div.Section2
                        {page:Section2;}
                        </style>
                    </head>
                    <body>
                        <div class=Section2>
                    ";//邊界-上右下左
        StringBuilder sb = new StringBuilder();
        sb.AppendLine(s);
        Util.OutputTxt(sb + 列印模式新增表頭 + Export.Render(), "1", "" + DateTime.Now.ToString("yyyyMMddHHmmss"));

    }