using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class style_clientautosize : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string js = "var spid='" + FpSpread1.ClientID + "';"; ClientScript.RegisterStartupScript(this.GetType(), "onStartUpScript", js, true); if (IsPostBack) { return; } // SPREADの設定 InitSpread(FpSpread1); // シート設定 InitSpreadStyles(FpSpread1.Sheets[0]); } private void InitSpread(FarPoint.Web.Spread.FpSpread spread) { //データ連結 System.Data.DataSet ds = new System.Data.DataSet(); ds.ReadXml(MapPath("../App_Data/datacol4.xml")); FpSpread1.DataSource = ds; spread.UseClipboard = false; spread.ClientAutoSize = true; FpSpread1.ClientAutoSizeMaxHeight = 300; FpSpread1.ClientAutoSizeMaxWidth = 500; } private void InitSpreadStyles(FarPoint.Web.Spread.SheetView sheet) { // フォントサイズの設定 sheet.DefaultStyle.Font.Size = FontUnit.Parse("80%"); sheet.ColumnHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%"); sheet.RowHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%"); sheet.SheetCorner.DefaultStyle.Font.Size = FontUnit.Parse("80%"); // 縦方向の揃え位置を中央に設定 sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle; } }
Partial Public Class style_clientautosize Inherits System.Web.UI.Page Protected Sub Page_Load(sender As Object, e As EventArgs) Dim js As String = "var spid='" + FpSpread1.ClientID + "';" ClientScript.RegisterStartupScript(Me.[GetType](), "onStartUpScript", js, True) If IsPostBack Then Return End If ' SPREADの設定 InitSpread(FpSpread1) ' シート設定 InitSpreadStyles(FpSpread1.Sheets(0)) End Sub Private Sub InitSpread(spread As FarPoint.Web.Spread.FpSpread) 'データ連結 Dim ds As New System.Data.DataSet() ds.ReadXml(MapPath("../App_Data/datacol4.xml")) FpSpread1.DataSource = ds spread.UseClipboard = False spread.ClientAutoSize = True FpSpread1.ClientAutoSizeMaxHeight = 300 FpSpread1.ClientAutoSizeMaxWidth = 500 End Sub Private Sub InitSpreadStyles(sheet As FarPoint.Web.Spread.SheetView) ' フォントサイズの設定 sheet.DefaultStyle.Font.Size = FontUnit.Parse("80%") sheet.ColumnHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%") sheet.RowHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%") sheet.SheetCorner.DefaultStyle.Font.Size = FontUnit.Parse("80%") ' 縦方向の揃え位置を中央に設定 sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle End Sub End Class
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="clientautosizemaxwidthheight.aspx.cs" Inherits="style_clientautosize" %> <%@ Register Assembly="FarPoint.Web.SpreadJ" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %> <asp:Content ID="Content1" ContentPlaceHolderID="HeaderPlaceHolder1" Runat="Server"> <script type="text/javascript"> function setColWidth() { var spread = document.getElementById(spid); var i; for (i = 0; i < spread.GetColCount(); i++) { spread.SizeToFit(i); } } </script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <input id="Button1" type="button" value="列幅の自動調整" onclick="setColWidth();" /> <FarPoint:FpSpread ID="FpSpread1" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid" BorderWidth="1px" Height="200" Width="400" style="position: relative;" > <CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight" ButtonShadowColor="ControlDark"> </CommandBar> <Sheets> <FarPoint:SheetView SheetName="Sheet1"> </FarPoint:SheetView> </Sheets> </FarPoint:FpSpread> </asp:Content>