using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class importexport_saveexcelfile : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { return; } // データ連結 System.Data.DataSet ds = new System.Data.DataSet(); ds.ReadXml(MapPath("../App_Data/data.xml")); FpSpread1.DataSource = ds; // SPREAD初期化 InitSpread(FpSpread1.Sheets[0]); } private void InitSpread(FarPoint.Web.Spread.SheetView sheet) { // SPREAD設定 FpSpread1.CommandBar.Visible = false; FpSpread1.CssClass = "spreadStyle"; FpSpread1.UseClipboard = false; // フォントサイズの設定 sheet.DefaultStyle.Font.Size = FontUnit.Point(9); sheet.ColumnHeader.DefaultStyle.Font.Size = FontUnit.Point(9); sheet.RowHeader.DefaultStyle.Font.Size = FontUnit.Point(9); sheet.SheetCorner.DefaultStyle.Font.Size = FontUnit.Point(9); // シート設定 sheet.PageSize = sheet.RowCount; sheet.Protect = false; // 列幅の設定 sheet.Columns[0].Width = 36; sheet.Columns[1].Width = 88; sheet.Columns[2].Width = 91; sheet.Columns[3].Width = 80; sheet.Columns[4].Width = 36; sheet.Columns[5].Width = 46; sheet.Columns[6].Width = 49; sheet.Columns[7].Width = 80; sheet.Columns[8].Width = 181; // 縦方向の揃え位置を中央に設定 sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle; } protected void Button1_Click(object sender, EventArgs e) { // クライアント側の変更を確定 FpSpread1.SaveChanges(); // MemoryStreamに内容を出力 System.IO.MemoryStream ms = new System.IO.MemoryStream(); FpSpread1.ActiveSheetView.SaveHtml(ms); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment;filename=spread.html"); Response.BinaryWrite(ms.ToArray()); ms.Flush(); ms.Close(); Response.End(); } }
Partial Class importexport_saveexcelfile Inherits System.Web.UI.Page Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If IsPostBack Then Return End If ' データ連結 Dim ds As New System.Data.DataSet() ds.ReadXml(MapPath("../App_Data/data.xml")) FpSpread1.DataSource = ds ' SPREAD初期化 InitSpread(FpSpread1.Sheets(0)) End Sub Private Sub InitSpread(sheet As FarPoint.Web.Spread.SheetView) ' SPREAD設定 FpSpread1.CommandBar.Visible = False FpSpread1.CssClass = "spreadStyle" FpSpread1.UseClipboard = False ' フォントサイズの設定 sheet.DefaultStyle.Font.Size = FontUnit.Point(9) sheet.ColumnHeader.DefaultStyle.Font.Size = FontUnit.Point(9) sheet.RowHeader.DefaultStyle.Font.Size = FontUnit.Point(9) sheet.SheetCorner.DefaultStyle.Font.Size = FontUnit.Point(9) ' シート設定 sheet.PageSize = sheet.RowCount sheet.Protect = False ' 列幅の設定 sheet.Columns(0).Width = 36 sheet.Columns(1).Width = 88 sheet.Columns(2).Width = 91 sheet.Columns(3).Width = 80 sheet.Columns(4).Width = 36 sheet.Columns(5).Width = 46 sheet.Columns(6).Width = 49 sheet.Columns(7).Width = 80 sheet.Columns(8).Width = 181 ' 縦方向の揃え位置を中央に設定 sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle End Sub Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click ' クライアント側の変更を確定 FpSpread1.SaveChanges() ' MemoryStreamに内容を出力 Dim ms As New System.IO.MemoryStream() FpSpread1.ActiveSheetView.SaveHtml(ms) Response.Clear() Response.AddHeader("Content-Disposition", "attachment;filename=spread.html") Response.BinaryWrite(ms.ToArray()) ms.Flush() ms.Close() Response.[End]() End Sub End Class
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="savehtml.aspx.cs" Inherits="importexport_saveexcelfile" %> <%@ Register Assembly="FarPoint.Web.SpreadJ" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %> <asp:Content ID="Content1" ContentPlaceHolderID="HeaderPlaceHolder1" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <asp:Button ID="Button1" runat="server" Text="ダウンロード" onclick="Button1_Click" /> <FarPoint:FpSpread ID="FpSpread1" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid" BorderWidth="1px"> <CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight" ButtonShadowColor="ControlDark"> </CommandBar> <Sheets> <FarPoint:SheetView SheetName="Sheet1"> </FarPoint:SheetView> </Sheets> </FarPoint:FpSpread> </asp:Content>