1

「Microsoft.Office.Interop.Excel.dll」を使用してExcelファイルを生成していますが、展開サーバーでExcelのインストールが許可されていませんか?

Excelのインストールが必須であることを知っているので、私の質問は次のとおりです。

Excelをインストールせずに同じコードを展開する方法はありますか?

4

2 に答える 2

3

Excelのインストールが必須であることを知っているので、私の質問Excelをインストールせずに同じコードを展開する方法やその他の提案された方法はありますか?

いいえ、Excelのインストールは必須です。しかし、それがあなたが質問を始めた方法だったので、あなたはすでにそれを知っています。

ライブラリの名前(Microsoft.Office.Interop.Excel.dll)は良い手がかりです。相互運用性の略であるinteropと書かれています。そして、存在しないものと相互運用することはできません。したがって、Excelとの相互運用を容易にするDLLを使用するには、Excelをインストールする必要があります。

法的な質問をすべて無視しても、これは論理的に意味がありません。

本当にExcelをインストールできない場合は、Excelファイルを作成する他の方法を見つける必要があります。これを行うと主張するライブラリがいくつかありますが、それらには制限があります。例えば:

于 2012-08-02T04:47:46.700 に答える
1

これを試して
ください http://epplus.codeplex.com


このコードはhttp://epplus.codeplex.com

からのもので、 バイト配列を拡張子.xlsのファイルに保存できます

private void DumpExcel(DataTable tbl)
        {
            using (ExcelPackage pck = new ExcelPackage())
            {
                //Create the worksheet
                ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");

                //Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
                ws.Cells["A1"].LoadFromDataTable(tbl, true);

                //Format the header for column 1-3
                using (ExcelRange rng = ws.Cells["A1:C1"])
                {
                    rng.Style.Font.Bold = true;
                    rng.Style.Fill.PatternType = ExcelFillStyle.Solid;                      //Set Pattern for the background to Solid
                    rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(79, 129, 189));  //Set color to dark blue
                    rng.Style.Font.Color.SetColor(Color.White);
                }

                //Example how to Format Column 1 as numeric 
                using (ExcelRange col = ws.Cells[2, 1, 2 + tbl.Rows.Count, 1])
                {
                    col.Style.Numberformat.Format = "#,##0.00";
                    col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
                }

                //Write it back to the client
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", "attachment;  filename=ExcelDemo.xlsx");
                Response.BinaryWrite(pck.GetAsByteArray());
            }
        }
于 2012-08-02T05:49:26.247 に答える