Microsoft Excel ファイルのエクスポート

Excel ファイルのエクスポート

ファイルとしてエクスポート

Aspose.Cells.GridWeb コントロールのコンテンツを Excel ファイルとして保存するには:

  1. Aspose.Cells.GridWeb コントロールを Web フォームに追加します。
  2. 指定したパスに Excel ファイルとして作業を保存します。
  3. アプリケーションを実行します。

Aspose.Cells.GridWeb コントロールが Windows フォームに追加されると、コントロールは自動的にインスタンス化され、既定のサイズでフォームに追加されます。 Aspose.Cells.GridWeb コントロール オブジェクトを作成する必要はありません。コントロールをドラッグ アンド ドロップして使用を開始するだけです。

次のコード例は、グリッド コンテンツを Excel ファイルに保存する方法を示しています。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Generates a temporary file name.
string filename = Session.SessionID + "_out.xls";
string path = (this.Master as Site).GetDataDir() + "\\GridWebBasics\\";
// Saves to the file.
this.GridWeb1.SaveToExcelFile(path + filename);
// Sents the file to browser.
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=" + filename);
Response.WriteFile(path + filename);
Response.End();

上記のコード スニペットは、いくつかの方法で使用できます。一般的な方法は、クリックしたときにグリッド コンテンツを Excel ファイルに保存するボタンを追加することです。 Aspose.Cells.GridWeb は、タスクに対するより簡単なアプローチを提供します。 Aspose.Cells.GridWeb には SaveCommand というイベントがあります。上記のコード スニペットを SaveCommand イベントのイベント ハンドラに追加すると、ユーザーは Aspose.Cells.GridWeb の組み込みセーブボタン。

GridWeb の SaveCommand イベント

todo:画像_代替_文章

GridWeb の組み込みの [保存] ボタンをクリックして、グリッド コンテンツを Excel に保存する

todo:画像_代替_文章

ストリームとしてエクスポート

グリッド コンテンツをストリーム (たとえば、MemoryStream) に保存することもできます。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Generates a temporary file name.
string filename = Session.SessionID + "_out.xls";
string path = (this.Master as Site).GetDataDir() + "\\GridWebBasics\\";
FileStream fs = File.Create(path + filename);
// Saving Grid content of the control to a stream
GridWeb1.SaveToExcelFile(fs);
// Closing stream
fs.Close();
// Sents the file to browser.
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=" + filename);
Response.WriteFile(path + filename);
Response.End();