1

ClosedXMLSQL データ テーブルから Excel にデータをエクスポートするために使用しています。

これはエクスポートの一部です: (dt は SQL Server からのデータを含むデータテーブルです)

 using (XLWorkbook wb = new XLWorkbook())
            {
                wb.Worksheets.Add(dt);

                Response.Clear();
                Response.Buffer = true;
                Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.ContentType = "application/vnd.ms-excel";
                Response.AddHeader("content-disposition", "attachment;filename=Report.xlsx");
                using (MemoryStream MyMemoryStream = new MemoryStream())
                {
                    wb.SaveAs(MyMemoryStream);
                    MyMemoryStream.WriteTo(Response.OutputStream);
                    Response.Flush();
                    Response.End();
                }
            }

問題は次のとおりです。

  • すべての数字をエクスポートした後、テキストとして

  • 10 進数にはドットがありますが、カンマが必要です

Excel へのエクスポートを正しくフォーマットする方法を教えてください。

4

1 に答える 1

2

ClosedXmlDocumetnationに役立つかもしれません

DataTypes を使用してデータテーブルをマップする

     private DataTable GetTable()
    {

        DataTable table = new DataTable();
        table.Columns.Add("Dosage", typeof(int));
        table.Columns.Add("Drug", typeof(string));
        table.Columns.Add("Patient", typeof(string));
        table.Columns.Add("Date", typeof(DateTime));


        return table;
    }

        // From a DataTable
        var dataTable = GetTable();
        ws.Cell(7, 1).Value = "From DataTable";
        var tableWithData = ws.Cell(8, 1).InsertTable(dataTable.AsEnumerable());
        ws.Columns().AdjustToContents();

        wb.SaveAs("InsertingTables.xlsx");

また

            dataTable.Columns[0].DataType = typeof(Int32);
            dataTable.Columns[1].DataType = typeof(string);
            dataTable.Columns[2].DataType = typeof(Int32);

        //after this 
            wb.Worksheets.Add(dt);
于 2014-04-11T08:55:49.520 に答える