LoginSignup
9
8

More than 5 years have passed since last update.

C#でExcel Creatorを使ってみる

Last updated at Posted at 2015-03-17

C#でExcel Creatorを使うことになったので、
メモとして使い方を随時書いていこうと思う。

ちなみに公開使用しているのはExcel Creator8.0
Excel Creatorは実行環境にExcelが無くてOKみたいです。

Excelファイルを読み込んで編集する

xlsxCreator.OpenBook("Excelの保存先", "読み込みたいExcelファイル");
//なんか処理
xlsxCreator.CloseBook(true);//閉じる

シートの選択と名前の変更

xlsxCreator.SheetNo = 0;
xlsxCreator.SheetName = "シート名";

セルに値を入れる

//Pos(x, y)でセルの位置を指定
xlsxCreator.Pos(0, 0).Str = "値";

//Pos(x, y, x2, y2)でセルを結合して値をいれられる
xlsxCreator.Pos(0, 0, 1, 1).Str = "値";

画像の挿入

xlsxCreator.Pos(0, 0, 4, 4).Drawing.AddImage("画像のパス");

ASP.NETでExcelファイルをダウンロード

long offset = 0;
long size = new FileInfo("Excelファイルのパス").Length;
Response.Clear();
Response.ContentEncoding = System.Text.Encoding.GetEncoding("shift-jis");
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AppendHeader("content-disposition", "attachment; filename=ファイル名");
Response.WriteFile(filePaht, offset, size);
Response.End();
9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8