|
行、列のリサイズ
行や列のResizable プロパティにて、ユーザーが行または列のサイズを変更することができるかを設定します。
Resizable プロパティをFalseに設定することで、ユーザーによる行または列のサイズ変更を禁止することができます。
また、ユーザーにヘッダの行・列のサイズ変更を許可するには、SPREADのAllowHeaderResizeプロパティを設定します。
このサンプルではチェックボックスにより、行、列およびヘッダのリサイズを許可、禁止することができます。
| 製品ID | 製品分類 | 製品名 | 第1Q | 第2Q |
4月 | 5月 | 6月 | 7月 | 8月 | 9月 |
1 | 増 | 10001 | 乳製品 | 酪農ミルク | 5,500 | 5,000 | 4,500 | 6,000 | 5,500 | 5,000 |
2 | 減 | 20001 | 清涼飲料水 | いよかんドリンク | 1,000 | 3,000 | 2,700 | 2,700 | 1,000 | 3,000 |
3 | 増 | 20002 | 清涼飲料水 | ぶどうジュース | 3,000 | 3,500 | 4,800 | 4,800 | 3,000 | 3,500 |
4 | 増 | 20003 | 清涼飲料水 | マンゴードリンク | 2,000 | 1,000 | 500 | 1,050 | 2,000 | 1,000 |
5 | 並 | 30001 | ビール | 激辛ビール | 5,500 | 8,000 | 8,500 | 10,000 | 5,500 | 8,000 |
6 | 並 | 30002 | ビール | モルトビール | 3,000 | 3,500 | 2,780 | 4,000 | 3,000 | 3,500 |
7 | 増 | 20004 | 清涼飲料水 | ぶどうの街 | 500 | 300 | 200 | 700 | 500 | 300 |
8 | 減 | 30003 | ビール | オリエントの村 | 8,000 | 9,500 | 9,580 | 9,000 | 8,000 | 9,500 |
9 | 減 | 40002 | 焼酎 | 吟醸 ほめごろし | 6,000 | 7,000 | 9,000 | 9,500 | 6,000 | 7,000 |
10 | 並 | 40003 | 焼酎 | 大吟醸 オリエント | 1,000 | 5,000 | 6,000 | 5,000 | 1,000 | 5,000 |
|
ソースコード
別ウィンドウで表示
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
public partial class rowcolcell_rowcolresize : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) return;
// セル型の自動設定を無効化
FpSpread1.ActiveSheetView.DataAutoCellTypes = false;
// データ連結
DataSet ds = new DataSet();
ds.ReadXml(MapPath("../App_Data/datanum3.xml"));
FpSpread1.DataSource = ds;
// SPREAD初期化
InitSpread(FpSpread1.Sheets[0]);
CheckBox1.Attributes.Add("onclick", "SpCallBack('chgHeaderResize')");
CheckBox2.Attributes.Add("onclick", "SpCallBack('chgRowResize')");
CheckBox3.Attributes.Add("onclick", "SpCallBack('chgColResize')");
}
private void InitSpread(FarPoint.Web.Spread.SheetView sheet)
{
// SPREAD設定
FpSpread1.CssClass = "spreadStyle";
FpSpread1.UseClipboard = false;
FpSpread1.CommandBar.Visible = false;
// フォントサイズの設定
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.Columns[0].Width = 45;
sheet.Columns[1].Width = 85;
sheet.Columns[2].Width = 140;
sheet.Columns[3].Width = 40;
sheet.Columns[4].Width = 65;
sheet.Columns[5].Width = 65;
sheet.Columns[6].Width = 65;
sheet.Columns[7].Width = 65;
sheet.Columns[8].Width = 65;
sheet.Columns[9].Width = 65;
// 縦方向の揃え位置を中央に設定
sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle;
// 各列のセル型を設定
FarPoint.Web.Spread.GeneralCellType gnr = new FarPoint.Web.Spread.GeneralCellType();
gnr.FormatString = "#,##0";
sheet.Columns[4, 9].CellType = gnr;
sheet.Columns[4, 9].HorizontalAlign = HorizontalAlign.Right;
sheet.Columns[3].HorizontalAlign = HorizontalAlign.Center;
sheet.Columns[3].Visible = false;
// 列ヘッダを2行に設定
sheet.ColumnHeader.RowCount = 2;
sheet.ColumnHeader.AutoTextIndex = 0;
// 行ヘッダを2行に設定
sheet.RowHeader.ColumnCount = 2;
sheet.RowHeader.AutoTextIndex = 0;
// ヘッダ再設定
sheet.ColumnHeaderSpanModel.Add(0, 0, 2, 1);
sheet.ColumnHeaderSpanModel.Add(0, 1, 2, 1);
sheet.ColumnHeaderSpanModel.Add(0, 2, 2, 1);
sheet.ColumnHeaderSpanModel.Add(0, 3, 2, 1);
sheet.ColumnHeader.Cells[1, 4].Text = "4月";
sheet.ColumnHeader.Cells[1, 5].Text = "5月";
sheet.ColumnHeader.Cells[1, 6].Text = "6月";
sheet.ColumnHeader.Cells[1, 7].Text = "7月";
sheet.ColumnHeader.Cells[1, 8].Text = "8月";
sheet.ColumnHeader.Cells[1, 9].Text = "9月";
sheet.ColumnHeader.Cells[0, 4].Text = "第1Q";
sheet.ColumnHeaderSpanModel.Add(0, 4, 1, 3);
sheet.ColumnHeader.Cells[0, 7].Text = "第2Q";
sheet.ColumnHeaderSpanModel.Add(0, 7, 1, 3);
sheet.RowHeader.Cells[0, 1].Text = "増";
sheet.RowHeader.Cells[1, 1].Text = "減";
sheet.RowHeader.Cells[2, 1].Text = "増";
sheet.RowHeader.Cells[3, 1].Text = "増";
sheet.RowHeader.Cells[4, 1].Text = "並";
sheet.RowHeader.Cells[5, 1].Text = "並";
sheet.RowHeader.Cells[6, 1].Text = "増";
sheet.RowHeader.Cells[7, 1].Text = "減";
sheet.RowHeader.Cells[8, 1].Text = "減";
sheet.RowHeader.Cells[9, 1].Text = "並";
sheet.RowHeader.Cells[10,1].Text = "増";
sheet.RowHeader.Cells[11,1].Text = "増";
sheet.RowHeader.Cells[12,1].Text = "増";
sheet.RowHeader.Cells[13,1].Text = "減";
sheet.RowHeader.Cells[14,1].Text = "増";
sheet.RowHeader.Cells[15,1].Text = "増";
sheet.RowHeader.Cells[16,1].Text = "増";
// ヘッダのリサイズを許可しない
FpSpread1.AllowHeaderResize = false;
// 行・列のリサイズを許可しない
for (int i = 0; i < FpSpread1.Sheets[0].RowCount; i++)
{
FpSpread1.Sheets[0].Rows[i].Resizable = false;
}
for (int i = 0; i < FpSpread1.Sheets[0].ColumnCount; i++)
{
FpSpread1.Sheets[0].Columns[i].Resizable = false;
}
}
protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
{
if (e.CommandName == "chgHeaderResize")
{
FpSpread1.AllowHeaderResize = !FpSpread1.AllowHeaderResize;
}
else if (e.CommandName == "chgRowResize")
{
for (int i = 0; i < FpSpread1.Sheets[0].RowCount; i++)
{
FpSpread1.Sheets[0].Rows[i].Resizable = !FpSpread1.Sheets[0].Rows[i].Resizable;
}
}
else if (e.CommandName == "chgColResize")
{
for (int i = 0; i < FpSpread1.Sheets[0].ColumnCount; i++)
{
FpSpread1.Sheets[0].Columns[i].Resizable = !FpSpread1.Sheets[0].Columns[i].Resizable;
}
}
}
}
|
Partial Public Class rowcolcell_rowcolresize
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack Then
Return
End If
' セル型の自動設定を無効化
FpSpread1.ActiveSheetView.DataAutoCellTypes = False
' データ連結
Dim ds As New System.Data.DataSet()
ds.ReadXml(MapPath("../App_Data/datanum3.xml"))
FpSpread1.DataSource = ds
' SPREAD初期化
InitSpread(FpSpread1.Sheets(0))
CheckBox1.Attributes.Add("onclick", "SpCallBack('chgHeaderResize')")
CheckBox2.Attributes.Add("onclick", "SpCallBack('chgRowResize')")
CheckBox3.Attributes.Add("onclick", "SpCallBack('chgColResize')")
End Sub
Private Sub InitSpread(ByVal sheet As FarPoint.Web.Spread.SheetView)
' SPREAD設定
FpSpread1.CssClass = "spreadStyle"
FpSpread1.UseClipboard = False
FpSpread1.CommandBar.Visible = False
' フォントサイズの設定
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.Columns(0).Width = 45
sheet.Columns(1).Width = 85
sheet.Columns(2).Width = 140
sheet.Columns(3).Width = 40
sheet.Columns(4).Width = 65
sheet.Columns(5).Width = 65
sheet.Columns(6).Width = 65
sheet.Columns(7).Width = 65
sheet.Columns(8).Width = 65
sheet.Columns(9).Width = 65
' 縦方向の揃え位置を中央に設定
sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle
' 各列のセル型を設定
Dim gnr As New FarPoint.Web.Spread.GeneralCellType()
gnr.FormatString = "#,##0"
sheet.Columns(4, 9).CellType = gnr
sheet.Columns(4, 9).HorizontalAlign = HorizontalAlign.Right
sheet.Columns(3).HorizontalAlign = HorizontalAlign.Center
sheet.Columns(3).Visible = False
' 列ヘッダを2行に設定
sheet.ColumnHeader.RowCount = 2
sheet.ColumnHeader.AutoTextIndex = 0
' 行ヘッダを2行に設定
sheet.RowHeader.ColumnCount = 2
sheet.RowHeader.AutoTextIndex = 0
' ヘッダ再設定
sheet.ColumnHeaderSpanModel.Add(0, 0, 2, 1)
sheet.ColumnHeaderSpanModel.Add(0, 1, 2, 1)
sheet.ColumnHeaderSpanModel.Add(0, 2, 2, 1)
sheet.ColumnHeaderSpanModel.Add(0, 3, 2, 1)
sheet.ColumnHeader.Cells(1, 4).Text = "4月"
sheet.ColumnHeader.Cells(1, 5).Text = "5月"
sheet.ColumnHeader.Cells(1, 6).Text = "6月"
sheet.ColumnHeader.Cells(1, 7).Text = "7月"
sheet.ColumnHeader.Cells(1, 8).Text = "8月"
sheet.ColumnHeader.Cells(1, 9).Text = "9月"
sheet.ColumnHeader.Cells(0, 4).Text = "第1Q"
sheet.ColumnHeaderSpanModel.Add(0, 4, 1, 3)
sheet.ColumnHeader.Cells(0, 7).Text = "第2Q"
sheet.ColumnHeaderSpanModel.Add(0, 7, 1, 3)
sheet.RowHeader.Cells(0, 1).Text = "増"
sheet.RowHeader.Cells(1, 1).Text = "減"
sheet.RowHeader.Cells(2, 1).Text = "増"
sheet.RowHeader.Cells(3, 1).Text = "増"
sheet.RowHeader.Cells(4, 1).Text = "並"
sheet.RowHeader.Cells(5, 1).Text = "並"
sheet.RowHeader.Cells(6, 1).Text = "増"
sheet.RowHeader.Cells(7, 1).Text = "減"
sheet.RowHeader.Cells(8, 1).Text = "減"
sheet.RowHeader.Cells(9, 1).Text = "並"
sheet.RowHeader.Cells(10, 1).Text = "増"
sheet.RowHeader.Cells(11, 1).Text = "増"
sheet.RowHeader.Cells(12, 1).Text = "増"
sheet.RowHeader.Cells(13, 1).Text = "減"
sheet.RowHeader.Cells(14, 1).Text = "増"
sheet.RowHeader.Cells(15, 1).Text = "増"
sheet.RowHeader.Cells(16, 1).Text = "増"
' ヘッダのリサイズを許可しない
FpSpread1.AllowHeaderResize = False
' 行・列のリサイズを許可しない
For i As Integer = 0 To FpSpread1.Sheets(0).RowCount - 1
FpSpread1.Sheets(0).Rows(i).Resizable = False
Next
For i As Integer = 0 To FpSpread1.Sheets(0).ColumnCount - 1
FpSpread1.Sheets(0).Columns(i).Resizable = False
Next
End Sub
Protected Sub FpSpread1_ButtonCommand(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SpreadCommandEventArgs) Handles FpSpread1.ButtonCommand
If e.CommandName = "chgHeaderResize" Then
FpSpread1.AllowHeaderResize = Not FpSpread1.AllowHeaderResize
ElseIf e.CommandName = "chgRowResize" Then
For i As Integer = 0 To FpSpread1.Sheets(0).RowCount - 1
FpSpread1.Sheets(0).Rows(i).Resizable = Not FpSpread1.Sheets(0).Rows(i).Resizable
Next
ElseIf e.CommandName = "chgColResize" Then
For i As Integer = 0 To FpSpread1.Sheets(0).ColumnCount - 1
FpSpread1.Sheets(0).Columns(i).Resizable = Not FpSpread1.Sheets(0).Columns(i).Resizable
Next
End If
End Sub
End Class
|
<%@ Page MasterPageFile="~/MasterPage.master" Language="c#" AutoEventWireup="true"
Inherits="rowcolcell_rowcolresize" CodeFile="rowcolresize.aspx.cs" %>
<%@ Register Assembly="FarPoint.Web.SpreadJ" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<script type="text/javascript">
function SpCallBack(cmdnm) {
var spread = document.getElementById("<%= FpSpread1.ClientID %>");
spread.CallBack(cmdnm);
}
</script>
<asp:CheckBox ID="CheckBox1" runat="server" Text="ヘッダのリサイズを許可"
Checked="False" style="position: relative;" />
<asp:CheckBox ID="CheckBox2" runat="server" Text="行のリサイズを許可"
Checked="False" style="position: relative;" />
<asp:CheckBox ID="CheckBox3" runat="server" Text="列のリサイズを許可"
Checked="False" style="position: relative;" />
<farpoint:FpSpread ID="FpSpread1" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid"
BorderWidth="1px" onbuttoncommand="FpSpread1_ButtonCommand">
<CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight"
ButtonShadowColor="ControlDark" />
<Sheets>
<farpoint:SheetView SheetName="Sheet1">
</farpoint:SheetView>
</Sheets>
</farpoint:FpSpread>
</asp:Content>
|
|