ASP.NET アプリ (VB.NET コードビハインド) にセクションを追加しようとしています。これにより、ユーザーはデータベース データに基づいて生成する Excel ファイルとして返されるデータを取得できます。これにはいくつかの方法がありますが、それぞれに独自の欠点があります。どのようにデータを返しますか?できるだけクリーンでシンプルなものを探しています。
26 に答える
CSV
長所:
- 単純
短所:
- 他のロケールや異なる Excel 構成 (つまり、リスト区切り記号) では機能しない場合があります。
- 書式設定、数式などを適用できません
HTML
長所:
- まだかなりシンプル
- 簡単な書式設定と数式をサポート
短所:
- ファイルに xls という名前を付ける必要があります。Excel は、ネイティブではない Excel ファイルを開くことについて警告する場合があります。
- ワークブックごとに 1 つのワークシート
OpenXML (Office 2007 .XLSX)
長所:
- ネイティブ Excel 形式
- すべての Excel 機能をサポート
- Excel のインストール コピーを必要としない
- ピボットテーブルを生成できます
- オープン ソース プロジェクトEPPlusを使用して生成可能
短所:
- Excel 2007 以外での限定的な互換性 (現在は問題にならないはずです)
- サードパーティのコンポーネントを使用していない限り複雑
SpreadSheetML (オープン形式の XML)
長所:
- ネイティブの Excel 形式に比べてシンプル
- ほとんどの Excel 機能をサポート: 書式設定、スタイル、数式、ワークブックごとの複数シート
- Excel をインストールする必要はありません。
- サードパーティのライブラリは不要 - xml を書き出すだけ
- ドキュメントは Excel XP/2003/2007 で開くことができます
短所:
- 適切なドキュメントの欠如
- 古いバージョンの Excel (2000 より前) ではサポートされていません
- 書き込み専用。一度開いて Excel から変更を加えると、ネイティブ Excel に変換されます。
XLS (サードパーティ コンポーネントによって生成)
長所:
- すべての書式設定、数式などを含むネイティブ Excel ファイルを生成します。
短所:
- お金がかかる
- 依存関係を追加する
COM 相互運用
長所:
- ネイティブの Microsoft ライブラリを使用
- ネイティブ ドキュメントの読み取りサポート
短所:
- 非常に遅い
- 依存関係/バージョンの一致の問題
- 読み取り時の Web 使用の並行性/データ整合性の問題
- 非常に遅い
- Web 使用のスケーリングの問題 (同時実行とは異なります): サーバー上に重い Excel アプリのインスタンスを多数作成する必要があります
- Windows が必要
- 私はそれが遅いと言いましたか?
データを html テーブル セルとして出力し、その上に拡張子.xls
または.xlsx
拡張子を貼り付けると、Excel はそれをネイティブ ドキュメントのように開きます。この方法では、一部の限定的な書式設定や数式計算を実行することもできるため、CSV よりもはるかに強力です。また、HTML テーブルの出力は、ASP.Net などの Web プラットフォームから非常に簡単に実行できるはずです ;)
Excel ワークブック内に複数のワークシートまたは名前付きワークシートが必要な場合は、.xml という XML スキーマを介して同様のことを行うことができますSpreadSheetML
。これはOffice 2007 に同梱された新しい形式ではなく、Excel 2000 までさかのぼって機能するまったく異なる形式です。
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Author>Your_name_here</Author>
<LastAuthor>Your_name_here</LastAuthor>
<Created>20080625</Created>
<Company>ABC Inc</Company>
<Version>10.2625</Version>
</DocumentProperties>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>6135</WindowHeight>
<WindowWidth>8445</WindowWidth>
<WindowTopX>240</WindowTopX>
<WindowTopY>120</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
</Styles>
<Worksheet ss:Name="Sample Sheet 1">
<Table ss:ExpandedColumnCount="2" x:FullColumns="1" x:FullRows="1" ID="Table1">
<Column ss:Width="150" />
<Column ss:Width="200" />
<Row>
<Cell><Data ss:Type="Number">1</Data></Cell>
<Cell><Data ss:Type="Number">2</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">3</Data></Cell>
<Cell><Data ss:Type="Number">4</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">5</Data></Cell>
<Cell><Data ss:Type="Number">6</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">7</Data></Cell>
<Cell><Data ss:Type="Number">8</Data></Cell>
</Row>
</Table>
</Worksheet>
<Worksheet ss:Name="Sample Sheet 2">
<Table ss:ExpandedColumnCount="2" x:FullColumns="1" x:FullRows="1" ID="Table2">
<Column ss:Width="150" />
<Column ss:Width="200" />
<Row>
<Cell><Data ss:Type="String">A</Data></Cell>
<Cell><Data ss:Type="String">B</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">C</Data></Cell>
<Cell><Data ss:Type="String">D</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">E</Data></Cell>
<Cell><Data ss:Type="String">F</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">G</Data></Cell>
<Cell><Data ss:Type="String">H</Data></Cell>
</Row>
</Table>
</Worksheet>
</Workbook>
DataTableからの場合:
public static void DataTabletoXLS(DataTable DT, string fileName)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "utf-16";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}.xls", fileName));
HttpContext.Current.Response.ContentType = "application/ms-excel";
string tab = "";
foreach (DataColumn dc in DT.Columns)
{
HttpContext.Current.Response.Write(tab + dc.ColumnName.Replace("\n", "").Replace("\t", ""));
tab = "\t";
}
HttpContext.Current.Response.Write("\n");
int i;
foreach (DataRow dr in DT.Rows)
{
tab = "";
for (i = 0; i < DT.Columns.Count; i++)
{
HttpContext.Current.Response.Write(tab + dr[i].ToString().Replace("\n", "").Replace("\t", ""));
tab = "\t";
}
HttpContext.Current.Response.Write("\n");
}
HttpContext.Current.Response.End();
}
Gridviewから:
public static void GridviewtoXLS(GridView gv, string fileName)
{
int DirtyBit = 0;
int PageSize = 0;
if (gv.AllowPaging == true)
{
DirtyBit = 1;
PageSize = gv.PageSize;
gv.AllowPaging = false;
gv.DataBind();
}
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
HttpContext.Current.Response.AddHeader(
"content-disposition", string.Format("attachment; filename={0}.xls", fileName));
HttpContext.Current.Response.ContentType = "application/ms-excel";
using (StringWriter sw = new StringWriter())
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
// Create a table to contain the grid
Table table = new Table();
// include the gridline settings
table.GridLines = gv.GridLines;
// add the header row to the table
if (gv.HeaderRow != null)
{
Utilities.Export.PrepareControlForExport(gv.HeaderRow);
table.Rows.Add(gv.HeaderRow);
}
// add each of the data rows to the table
foreach (GridViewRow row in gv.Rows)
{
Utilities.Export.PrepareControlForExport(row);
table.Rows.Add(row);
}
// add the footer row to the table
if (gv.FooterRow != null)
{
Utilities.Export.PrepareControlForExport(gv.FooterRow);
table.Rows.Add(gv.FooterRow);
}
// render the table into the htmlwriter
table.RenderControl(htw);
// render the htmlwriter into the response
HttpContext.Current.Response.Write(sw.ToString().Replace("£", ""));
HttpContext.Current.Response.End();
}
if (DirtyBit == 1)
{
gv.PageSize = PageSize;
gv.AllowPaging = true;
gv.DataBind();
}
}
private static void PrepareControlForExport(Control control)
{
for (int i = 0; i < control.Controls.Count; i++)
{
Control current = control.Controls[i];
if (current is LinkButton)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as LinkButton).Text));
}
else if (current is ImageButton)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as ImageButton).AlternateText));
}
else if (current is HyperLink)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as HyperLink).Text));
}
else if (current is DropDownList)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as DropDownList).SelectedItem.Text));
}
else if (current is CheckBox)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as CheckBox).Checked ? "True" : "False"));
}
if (current.HasControls())
{
Utilities.Export.PrepareControlForExport(current);
}
}
}
これは、SpreadML の無料のラッパーです。うまく機能します。
与えられた回答と同僚との協議に基づいて、最良の解決策は XML ファイルまたは HTML テーブルのいずれかを生成し、添付ファイルとしてプッシュすることであると思われます。私の同僚が推奨する 1 つの変更は、データ (つまり、HTML テーブル) を直接 Response オブジェクトに書き込めるようにすることです。これにより、ファイルを書き出す必要がなくなります。これは、アクセス許可の問題や I/O の問題で面倒になる可能性があります。競合、およびスケジュールされたパージが確実に行われるようにします。
ここにコードのスニペットがあります...私はまだこれをチェックしておらず、呼び出されたすべてのコードを提供していませんが、アイデアをよく表していると思います.
Dim uiTable As HtmlTable = GetUiTable(groupedSumData)
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition", String.Format("inline; filename=OSSummery{0:ddmmssf}.xls", DateTime.Now))
Dim writer As New System.IO.StringWriter()
Dim htmlWriter As New HtmlTextWriter(writer)
uiTable.RenderControl(htmlWriter)
Response.Write(writer.ToString)
Response.End()
Excel は HTML を理解するので、データを HTML テーブルとして拡張子 .xls の一時ファイルに書き出すだけで、ファイルの FileInfo を取得し、
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fi.Name);
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(fi.FullName);
Response.End();
一時ファイルを回避したい場合は、WriteFile を使用する代わりに、メモリ内ストリームに書き込み、バイトを書き戻すことができます。
content-length ヘッダーが省略されている場合は、html を直接書き戻すことができますが、これはすべてのブラウザーで常に正しく機能するとは限りません。
個人的にはXML方式の方が好きです。データベースのデータを Dataset で返し、それを XMl に保存します。次に、適切なドキュメントをフォーマットする変換ルールを含む xslt ファイルを作成します。単純な XML 変換で作業が完了します。これの最も良い部分は、セルの書式設定、条件付き書式設定、ヘッダーとフッターの設定、さらには印刷範囲の設定を行うことができることです。
OpenXMLに基づく無料のオープンソースExcel生成ライブラリをお勧めします
それは数ヶ月前に私を助けました。
常にデータグリッドからデータをエクスポートしてエクセルにします。HTMLに変換してからExcelファイルに書き込む
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Response.AddHeader("content-disposition", "fileattachment;filename=YOURFILENAME.xls")
Me.EnableViewState = False
Dim sw As System.IO.StringWriter = New System.IO.StringWriter
Dim hw As HtmlTextWriter = New HtmlTextWriter(sw)
ClearControls(grid)
grid.RenderControl(hw)
Response.Write(sw.ToString())
Response.End()
この方法の唯一の問題は、多くのグリッドにボタンまたはリンクが含まれているため、これも必要になることです。
'needed to export grid to excel to remove link button control and represent as text
Private Sub ClearControls(ByVal control As Control)
Dim i As Integer
For i = control.Controls.Count - 1 To 0 Step -1
ClearControls(control.Controls(i))
Next i
If TypeOf control Is System.Web.UI.WebControls.Image Then
control.Parent.Controls.Remove(control)
End If
If (Not TypeOf control Is TableCell) Then
If Not (control.GetType().GetProperty("SelectedItem") Is Nothing) Then
Dim literal As New LiteralControl
control.Parent.Controls.Add(literal)
Try
literal.Text = CStr(control.GetType().GetProperty("SelectedItem").GetValue(control, Nothing))
Catch
End Try
control.Parent.Controls.Remove(control)
Else
If Not (control.GetType().GetProperty("Text") Is Nothing) Then
Dim literal As New LiteralControl
control.Parent.Controls.Add(literal)
literal.Text = CStr(control.GetType().GetProperty("Text").GetValue(control, Nothing))
control.Parent.Controls.Remove(control)
End If
End If
End If
Return
End Sub
どこかで、うまく機能していることがわかりました。
これを数回実行しましたが、毎回最も簡単な方法は、単純に CSV (カンマ区切り値) ファイルを返すことでした。Excel はそれを完璧にインポートし、比較的高速にインポートできます。
ストアド プロシージャから取得したレポートを次に示します。結果は Excel にエクスポートされます。ADO.NETの代わりにADOを使用し、その理由はこの行です
oSheet.Cells(2, 1).copyfromrecordset(rst1)
これはほとんどの作業を行いますが、ado.net では使用できません。
‘Calls stored proc in SQL Server 2000 and puts data in Excel and ‘formats it
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cnn As ADODB.Connection
cnn = New ADODB.Connection
cnn.Open("Provider=SQLOLEDB;data source=xxxxxxx;" & _
"database=xxxxxxxx;Trusted_Connection=yes;")
Dim cmd As New ADODB.Command
cmd.ActiveConnection = cnn
cmd.CommandText = "[sp_TomTepley]"
cmd.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
cmd.CommandTimeout = 0
cmd.Parameters.Refresh()
Dim rst1 As ADODB.Recordset
rst1 = New ADODB.Recordset
rst1.Open(cmd)
Dim oXL As New Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
'oXL = CreateObject("excel.application")
oXL.Visible = True
oWB = oXL.Workbooks.Add
oSheet = oWB.ActiveSheet
Dim Column As Integer
Column = 1
Dim fld As ADODB.Field
For Each fld In rst1.Fields
oXL.Workbooks(1).Worksheets(1).Cells(1, Column).Value = fld.Name
oXL.Workbooks(1).Worksheets(1).cells(1, Column).Interior.ColorIndex = 15
Column = Column + 1
Next fld
oXL.Workbooks(1).Worksheets(1).name = "Tom Tepley Report"
oSheet.Cells(2, 1).copyfromrecordset(rst1)
oXL.Workbooks(1).Worksheets(1).Cells.EntireColumn.AutoFit()
oXL.Visible = True
oXL.UserControl = True
rst1 = Nothing
cnn.Close()
Beep()
End Sub
Microsoft.Office.Interop 名前空間を介した COM Interop は避けてください。それは非常に遅く、信頼性が低く、スケーラブルではありません。マゾヒストには適用されません。
GridView にデータを入力すると、この関数を使用して HTML 形式のデータを取得できますが、ブラウザーにそれが Excel ファイルであることを示します。
Public Sub ExportToExcel(ByVal fileName As String, ByVal gv As GridView)
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", fileName))
HttpContext.Current.Response.ContentType = "application/ms-excel"
Dim sw As StringWriter = New StringWriter
Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
Dim table As Table = New Table
table.GridLines = gv.GridLines
If (Not (gv.HeaderRow) Is Nothing) Then
PrepareControlForExport(gv.HeaderRow)
table.Rows.Add(gv.HeaderRow)
End If
For Each row As GridViewRow In gv.Rows
PrepareControlForExport(row)
table.Rows.Add(row)
Next
If (Not (gv.FooterRow) Is Nothing) Then
PrepareControlForExport(gv.FooterRow)
table.Rows.Add(gv.FooterRow)
End If
table.RenderControl(htw)
HttpContext.Current.Response.Write(sw.ToString)
HttpContext.Current.Response.End()
End Sub
Private Sub PrepareControlForExport(ByVal control As Control)
Dim i As Integer = 0
Do While (i < control.Controls.Count)
Dim current As Control = control.Controls(i)
If (TypeOf current Is LinkButton) Then
control.Controls.Remove(current)
control.Controls.AddAt(i, New LiteralControl(CType(current, LinkButton).Text))
ElseIf (TypeOf current Is ImageButton) Then
control.Controls.Remove(current)
control.Controls.AddAt(i, New LiteralControl(CType(current, ImageButton).AlternateText))
ElseIf (TypeOf current Is HyperLink) Then
control.Controls.Remove(current)
control.Controls.AddAt(i, New LiteralControl(CType(current, HyperLink).Text))
ElseIf (TypeOf current Is DropDownList) Then
control.Controls.Remove(current)
control.Controls.AddAt(i, New LiteralControl(CType(current, DropDownList).SelectedItem.Text))
ElseIf (TypeOf current Is CheckBox) Then
control.Controls.Remove(current)
control.Controls.AddAt(i, New LiteralControl(CType(current, CheckBox).Checked))
End If
If current.HasControls Then
PrepareControlForExport(current)
End If
i = i + 1
Loop
End Sub
http://officehelper.codeplex.com/documentationのライブラリを使用して、きれいにフォーマットされた Excel ファイルを簡単に作成できます。
Web サーバーに Microsoft Office をインストールする必要はありません。
これがイントラネット用であり、アクセス許可を設定して IE を委任できると仮定すると、Excel を駆動する JScript/VBScriptを使用してワークブック クライアント側を生成できます。これにより、サーバー上で Excel を自動化する手間をかけずに、ネイティブの Excel 書式設定が可能になります。
かなりニッチなシナリオを除いて、このアプローチを本当にお勧めできるかどうかはわかりませんが、古典的な ASP の全盛期にはかなり一般的でした。
これは、データテーブルを CSV としてストリーミングするソリューションです。速く、きれいで、簡単で、入力のコンマを処理します。
public static void ExportToExcel(DataTable data, HttpResponse response, string fileName)
{
response.Charset = "utf-8";
response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.ContentType = "text/csv";
response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
for (int i = 0; i < data.Columns.Count; i++)
{
response.Write(data.Columns[i].ColumnName);
response.Write(i == data.Columns.Count - 1 ? "\n" : ",");
}
foreach (DataRow row in data.Rows)
{
for (int i = 0; i < data.Columns.Count; i++)
{
response.Write(String.Format("\"{0}\"", row[i].ToString()));
response.Write(i == data.Columns.Count - 1 ? "\n" : ",");
}
}
response.End();
}
この回答に似ている上記の解決策の 1 つを使用して遭遇した問題の 1 つは、コンテンツを添付ファイルとしてプッシュする場合です (ms 以外のブラウザーで最もクリーンな解決策であることがわかりました)。 、Excel 2000-2003 で開くと、そのタイプは "Excel Web ページ" であり、ネイティブの Excel ドキュメントではありません。
次に、Excel 内から [ファイルの種類] を使用して Excel ドキュメントに変換する方法をユーザーに説明する必要があります。ユーザーがこのドキュメントを編集してサイトに再アップロードする必要がある場合、これは面倒です。
私のお勧めは、CSV を使用することです。これは簡単で、ユーザーが Excel 内から開いた場合、Excel は少なくともネイティブ形式で保存するように求めます。
データに基づいて CSV ファイルを作成するだけです。これが最もクリーンで、Excel が適切にサポートしているためです。しかし、より柔軟な形式が必要な場合は、実際の Excel ファイルを生成するためのサードパーティ ツールがいくつかあると確信しています。
CSV が最も簡単な方法です。ほとんどの場合、Excel にリンクされています。それ以外の場合は、自動化 API または XML 形式を使用する必要があります。API と XML の使用はそれほど難しくありません。
私は (上記のように) CSV ルートを使用するか、最近では Infragistics NetAdvantage を使用してファイルを生成することがよくあります。(Infragistics が使用されているほとんどの場合、既存の UltraWebGrid をエクスポートしているだけです。これは、追加の書式設定の微調整が必要でない限り、基本的に 1 つの LOC ソリューションです。Excel/BIFF ファイルを手動で生成することもできます。ただし、必要になることはめったにありません。)
男、.netではそれができるコンポーネントがあると思いますが、クラシックASPでは、htmlテーブルを作成し、ページのMIMEタイプをvnd/msexcelに変更しています。gridview は html テーブルであるため、gridview を使用して MIME タイプを変更すると、うまくいくと思います。
「これらの数値はテキストとして保存されているようです」という緑色の三角形を回避する唯一の確実な方法は、Open XML 形式を使用することです。避けられない緑色の三角形を避けるためだけに、それを使用する価値があります。
私が見た Excel レポートの最良の方法は、XML 拡張子を使用して XML でデータを書き出し、正しいコンテンツ タイプでクライアントにストリーミングすることです。(申込書/xls)
これは、基本的な書式設定が必要なレポートで機能し、テキスト比較ツールを使用して既存のスプレッドシートと比較できます。
もちろん、いつでもサードパーティのコンポーネントを使用できます。個人的には、Spire.XLS http://www.e-iceblue.com/xls/xlsintro.htmで良い経験をしました。
このコンポーネントは、アプリケーション内で非常に簡単に使用できます。
Workbook workbook = new Workbook();
//Load workbook from disk.
workbook.LoadFromFile(@"Data\EditSheetSample.xls");
//Initailize worksheet
Worksheet sheet = workbook.Worksheets[0];
//Writes string
sheet.Range["B1"].Text = "Hello,World!";
//Writes number
sheet.Range["B2"].NumberValue = 1234.5678;
//Writes date
sheet.Range["B3"].DateTimeValue = System.DateTime.Now;
//Writes formula
sheet.Range["B4"].Formula = "=1111*11111";
workbook.SaveToFile("Sample.xls");
CSV ファイルの代わりに Excel を使用する必要がある場合は、サーバー上の Excel インスタンスで OLE オートメーションを使用する必要があります。これを行う最も簡単な方法は、テンプレート ファイルを用意し、プログラムでデータを入力することです。別のファイルに保存します。
チップ:
- インタラクティブにしないでください。ユーザーにプロセスを開始してもらい、ファイルへのリンクを含むページを投稿してもらいます。これにより、スプレッドシートの生成中に発生する可能性のあるパフォーマンスの問題が軽減されます。
- 前に説明したように、テンプレートを使用します。変更しやすくなります。
- Excel がダイアログをポップアップしないように設定されていることを確認してください。Web サーバーでは、これにより Excel インスタンス全体がハングします。
- Excel インスタンスを別のサーバー (できればファイアウォールの背後) に保持して、潜在的なセキュリティ ホールとして公開されないようにします。
- リソースの使用状況に注意してください。OLE オートメーション インターフェイス (PIA はこれに対するシムにすぎません) を介してスプレッドシートを生成することは、かなり負荷の高いプロセスです。これを大量のデータにスケーリングする必要がある場合は、アーキテクチャをある程度賢くする必要があるかもしれません。
ファイルの形式が少し基本的であることを気にしない場合は、「MIME タイプを使用して Excel をだまして HTML テーブルを開く」アプローチのいくつかが機能します。また、これらのアプローチは、CPU の負荷の高い作業をクライアントに押し付けます。スプレッドシートの形式を細かく制御したい場合は、おそらく Excel 自体を使用して上記のようにファイルを生成する必要があります。