1

asp.net プロジェクトで c# を使用して smartxls を使用しています。次のコードがあります。

var excel = new SmartXLS.WorkBook();
string projPath = AppDomain.CurrentDomain.BaseDirectory;
excel.readXLSX(projPath + @"ExcelTemplates\" + template);
excel.ImportDataTable(....)
Response.ContentType = "application/vnd.ms-excel";
excel.write(Context.REsponse.OutputStream);

私のデータは aspx ページのページ リンクで直接開かれますが、開くと自動的にファイルに default.xls という名前が付けられます。この名前を変更する方法がわかりません。私はexcel.setSheetNameとexcel.DefinedNameを試しましたが、開いたときにExcelシートの名前を変更していません。常にdefault.xlsです。上記のコードでこの名前を設定する方法を知っている人はいますか? 書き込み時に C:\filename のようなパスに直接保存すると名前を変更できることはわかっていますが、特定の名前を付けて、ボタンまたはリンクのクリックでクライアントに対して自動的に開く必要があります。

ありがとう

4

1 に答える 1

2

ファイル名を明示的に指定する必要があります。

Response.ContentType = "application/vnd.ms-excel";

// この行を追加

Response.Addheader "Content-Disposition", "attachment;Filename=" & youfileName& ".xls"

Excel.write(Context.REsponse.OutputStream);

于 2010-11-09T23:01:57.657 に答える