パスワード付きのExcelファイルを出力したい
対象製品
SPREAD for ASP.NET 8.0J
詳細
SaveExcel メソッドのオーバーロードにより、パスワードを設定したExcelファイルを出力することができます。
◎サンプルコード(VB)
◎サンプルコード(C#)
◎サンプルコード(VB)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack Then
Return
End If
' テストデータの設定
FpSpread1.ActiveSheetView.Cells(1, 1).Value = "test"
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
' クライアントの変更を確定
FpSpread1.SaveChanges()
Dim pathname As String = HttpContext.Current.Server.MapPath(Request.ApplicationPath & "/")
Dim filename As String = pathname + "test.xls"
Dim password As String = "testpass"
FpSpread1.SaveExcel(filename, password)
End Sub
If IsPostBack Then
Return
End If
' テストデータの設定
FpSpread1.ActiveSheetView.Cells(1, 1).Value = "test"
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
' クライアントの変更を確定
FpSpread1.SaveChanges()
Dim pathname As String = HttpContext.Current.Server.MapPath(Request.ApplicationPath & "/")
Dim filename As String = pathname + "test.xls"
Dim password As String = "testpass"
FpSpread1.SaveExcel(filename, password)
End Sub
◎サンプルコード(C#)
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
return;
}
// テストデータの設定
FpSpread1.ActiveSheetView.Cells[1, 1].Value = "test";
}
protected void Button1_Click(object sender, EventArgs e)
{
// クライアントの変更を確定
FpSpread1.SaveChanges();
string pathname = HttpContext.Current.Server.MapPath(Request.ApplicationPath + "/");
string filename = pathname + "test.xls";
string password = "testpass";
FpSpread1.SaveExcel(filename, password);
}
{
if (IsPostBack)
{
return;
}
// テストデータの設定
FpSpread1.ActiveSheetView.Cells[1, 1].Value = "test";
}
protected void Button1_Click(object sender, EventArgs e)
{
// クライアントの変更を確定
FpSpread1.SaveChanges();
string pathname = HttpContext.Current.Server.MapPath(Request.ApplicationPath + "/");
string filename = pathname + "test.xls";
string password = "testpass";
FpSpread1.SaveExcel(filename, password);
}
キーワード
インポート/エクスポート