|
列幅変更の同期
クライアント側スクリプトで提供されるonColWidthChanged イベントは列幅が変更されたタイミングで発生します。
このサンプルでは上下いずれかのSPREADで列幅が変更されたタイミングで、もう一方のSPREADの列幅を再設定することで
2つのSPREADの列幅の同期をとっています。
列幅の変更にはSetColWidthメソッドを使用しています。
| 製品ID | 製品分類 | 製品名 | 4月計画 | 5月計画 | 6月計画 | 7月計画 | 8月計画 | 9月計画 | 10月計画 | 11月計画 | 12月計画 | 1月計画 | 2月計画 | 3月計画 |
1 | 10001 | 乳製品 | 酪農ミルク | 5,500 | 5,000 | 4,500 | 6,000 | 5,500 | 5,000 | 4,500 | 6,000 | 5,500 | 5,000 | 4,500 | 6,000 |
2 | 20001 | 清涼飲料水 | いよかんドリンク | 1,000 | 3,000 | 2,700 | 2,700 | 1,000 | 3,000 | 2,700 | 2,700 | 1,000 | 3,000 | 2,700 | 2,700 |
3 | 20002 | 清涼飲料水 | ぶどうジュース | 3,000 | 3,500 | 4,800 | 4,800 | 3,000 | 3,500 | 4,800 | 4,800 | 3,000 | 3,500 | 4,800 | 4,800 |
4 | 20003 | 清涼飲料水 | マンゴードリンク | 2,000 | 1,000 | 500 | 1,050 | 2,000 | 1,000 | 500 | 1,050 | 2,000 | 1,000 | 500 | 1,050 |
5 | 30001 | ビール | 激辛ビール | 5,500 | 8,000 | 8,500 | 10,000 | 5,500 | 8,000 | 8,500 | 10,000 | 5,500 | 8,000 | 8,500 | 10,000 |
6 | 30002 | ビール | モルトビール | 3,000 | 3,500 | 2,780 | 4,000 | 3,000 | 3,500 | 2,780 | 4,000 | 3,000 | 3,500 | 2,780 | 4,000 |
7 | 20004 | 清涼飲料水 | ぶどうの街 | 500 | 300 | 200 | 700 | 500 | 300 | 200 | 700 | 500 | 300 | 200 | 700 |
8 | 30003 | ビール | オリエントの村 | 8,000 | 9,500 | 9,580 | 9,000 | 8,000 | 9,500 | 9,580 | 9,000 | 8,000 | 9,500 | 9,580 | 9,000 |
9 | 40002 | 焼酎 | 吟醸 ほめごろし | 6,000 | 7,000 | 9,000 | 9,500 | 6,000 | 7,000 | 9,000 | 9,500 | 6,000 | 7,000 | 9,000 | 9,500 |
10 | 40003 | 焼酎 | 大吟醸 オリエント | 1,000 | 5,000 | 6,000 | 5,000 | 1,000 | 5,000 | 6,000 | 5,000 | 1,000 | 5,000 | 6,000 | 5,000 |
|
| 製品ID | 製品分類 | 製品名 | 4月実績 | 5月実績 | 6月実績 | 7月実績 | 8月実績 | 9月実績 | 10月実績 | 11月実績 | 12月実績 | 1月実績 | 2月実績 | 3月実績 |
1 | 10001 | 乳製品 | 酪農ミルク | 5,600 | 5,100 | 4,600 | 6,100 | 5,600 | 5,100 | 4,600 | 6,100 | 5,600 | 5,100 | 4,600 | 6,100 |
2 | 20001 | 清涼飲料水 | いよかんドリンク | 1,100 | 3,100 | 2,800 | 2,800 | 1,100 | 3,100 | 2,800 | 2,800 | 1,100 | 3,100 | 2,800 | 2,800 |
3 | 20002 | 清涼飲料水 | ぶどうジュース | 3,100 | 3,600 | 4,900 | 4,900 | 3,100 | 3,600 | 4,900 | 4,900 | 3,100 | 3,600 | 4,900 | 4,900 |
4 | 20003 | 清涼飲料水 | マンゴードリンク | 2,100 | 1,100 | 600 | 1,150 | 2,100 | 1,100 | 600 | 1,150 | 2,100 | 1,100 | 600 | 1,150 |
5 | 30001 | ビール | 激辛ビール | 5,600 | 8,100 | 8,600 | 10,100 | 5,600 | 8,100 | 8,600 | 10,100 | 5,600 | 8,100 | 8,600 | 10,100 |
6 | 30002 | ビール | モルトビール | 3,100 | 3,600 | 2,880 | 4,100 | 3,100 | 3,600 | 2,880 | 4,100 | 3,100 | 3,600 | 2,880 | 4,100 |
7 | 20004 | 清涼飲料水 | ぶどうの街 | 600 | 400 | 300 | 800 | 600 | 400 | 300 | 800 | 600 | 400 | 300 | 800 |
8 | 30003 | ビール | オリエントの村 | 8,100 | 9,600 | 9,680 | 9,100 | 8,100 | 9,600 | 9,680 | 9,100 | 8,100 | 9,600 | 9,680 | 9,100 |
9 | 40002 | 焼酎 | 吟醸 ほめごろし | 6,100 | 7,100 | 9,100 | 9,600 | 6,100 | 7,100 | 9,100 | 9,600 | 6,100 | 7,100 | 9,100 | 9,600 |
10 | 40003 | 焼酎 | 大吟醸 オリエント | 1,100 | 5,100 | 6,100 | 5,100 | 1,100 | 5,100 | 6,100 | 5,100 | 1,100 | 5,100 | 6,100 | 5,100 |
11 | 40005 | 焼酎 | 麦焼酎 ちこちこ | 1,100 | 1,600 | 1,300 | 1,358 | 1,100 | 1,600 | 1,300 | 1,358 | 1,100 | 1,600 | 1,300 | 1,358 |
12 | 10002 | 乳製品 | 酪農ミルク(低脂肪) | 601 | 302 | 480 | 556 | 601 | 302 | 480 | 556 | 601 | 302 | 480 | 556 |
|
ソースコード
別ウィンドウで表示
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
public partial class clientsynchrocolwidth : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// クライアントイベントの設定
string js = "var spid1='" + FpSpread1.ClientID + "';";
js += "var spid2='" + FpSpread2.ClientID + "';";
js += "setTimeout(\"inite()\", 1000);" + "\r\n";
js += "function inite()" + "\r\n";
js += "{" + "\r\n";
js += " var s1=document.getElementById(spid1);" + "\r\n";
js += " var s2=document.getElementById(spid2);" + "\r\n";
js += " if (document.all) {" + "\r\n";
js += " if (s1.addEventListener) {" + "\r\n";
js += " s1.addEventListener(\"ColWidthChanged\", cwidth1, false);" + "\r\n";
js += " s2.addEventListener(\"ColWidthChanged\", cwidth2, false);" + "\r\n";
js += " } else {" + "\r\n";
js += " s1.onColWidthChanged = cwidth1;" + "\r\n";
js += " s2.onColWidthChanged = cwidth2;" + "\r\n";
js += " }" + "\r\n";
js += " } else {" + "\r\n";
js += " s1.addEventListener(\"ColWidthChanged\", cwidth1, false);" + "\r\n";
js += " s2.addEventListener(\"ColWidthChanged\", cwidth2, false);" + "\r\n";
js += " }" + "\r\n";
js += "}" + "\r\n";
ClientScript.RegisterStartupScript(this.GetType(), "onStartUpScript", js, true);
if (IsPostBack) return;
// セル型の自動設定を無効化
FpSpread1.ActiveSheetView.DataAutoCellTypes = false;
FpSpread2.ActiveSheetView.DataAutoCellTypes = false;
// データ連結
DataSet ds1 = new DataSet();
ds1.ReadXml(MapPath("../App_Data/datapln.xml"));
FpSpread1.DataSource = ds1;
DataSet ds2 = new DataSet();
ds2.ReadXml(MapPath("../App_Data/datares.xml"));
FpSpread2.DataSource = ds2;
FarPoint.Web.Spread.SheetView sheet1 = FpSpread1.Sheets[0];
FarPoint.Web.Spread.SheetView sheet2 = FpSpread2.Sheets[0];
// SPREAD初期化
InitSpread(sheet1,FpSpread1);
InitSpread(sheet2,FpSpread2);
}
private void InitSpread(FarPoint.Web.Spread.SheetView sheet,FarPoint.Web.Spread.FpSpread spread)
{
// SPREAD設定
spread.CommandBar.Visible = false;
spread.Style.Add("position", "relative");
spread.Width = 650;
spread.Height = 150;
spread.UseClipboard = 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.PageSize = sheet.RowCount;
// 列幅の設定
sheet.Columns[0].Width = 50;
sheet.Columns[1].Width = 70;
sheet.Columns[2].Width = 130;
for (int i = 3; i < spread.ActiveSheetView.ColumnCount; i++)
{
sheet.Columns[i].Width = 65;
}
// 縦方向の揃え位置を中央に設定
sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle;
// 各列のセル型を設定
FarPoint.Web.Spread.GeneralCellType gnr = new FarPoint.Web.Spread.GeneralCellType();
gnr.FormatString = "#,##0";
sheet.Columns[3, sheet.ColumnCount - 1].CellType = gnr;
sheet.Columns[3, sheet.ColumnCount - 1].HorizontalAlign = HorizontalAlign.Right;
}
}
|
Partial Public Class clientsynchrocolwidth
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' クライアントイベント設定
Dim js As String = "var spid1='" + FpSpread1.ClientID & "';"
js += "var spid2='" + FpSpread2.ClientID & "';"
js += " var s1=document.getElementById(spid1);" & vbCr & vbLf
js += " var s2=document.getElementById(spid2);" & vbCr & vbLf
js += " if (document.all) {" & vbCr & vbLf
js += " s1.onColWidthChanged = cwidth1;" & vbCr & vbLf
js += " s2.onColWidthChanged = cwidth2;" & vbCr & vbLf
js += " } else {" & vbCr & vbLf
js += " s1.addEventListener(""ColWidthChanged"", cwidth1, false);" & vbCr & vbLf
js += " s2.addEventListener(""ColWidthChanged"", cwidth2, false);" & vbCr & vbLf
js += " }" & vbCr & vbLf
ClientScript.RegisterStartupScript(Me.GetType(), "onStartUpScript", js, True)
If IsPostBack Then
Return
End If
' セル型の自動設定を無効化
FpSpread1.ActiveSheetView.DataAutoCellTypes = False
FpSpread2.ActiveSheetView.DataAutoCellTypes = False
' データ連結
Dim ds1 As New System.Data.DataSet()
ds1.ReadXml(MapPath("../App_Data/datapln.xml"))
FpSpread1.DataSource = ds1
Dim ds2 As New System.Data.DataSet()
ds2.ReadXml(MapPath("../App_Data/datares.xml"))
FpSpread2.DataSource = ds2
Dim sheet1 As FarPoint.Web.Spread.SheetView = FpSpread1.Sheets(0)
Dim sheet2 As FarPoint.Web.Spread.SheetView = FpSpread2.Sheets(0)
' SPREAD初期化
InitSpread(sheet1, FpSpread1)
InitSpread(sheet2, FpSpread2)
End Sub
Private Sub InitSpread(ByVal sheet As FarPoint.Web.Spread.SheetView, ByVal spread As FarPoint.Web.Spread.FpSpread)
' SPREAD設定
spread.CommandBar.Visible = False
spread.Style.Add("position", "relative")
spread.Width = 650
spread.Height = 150
spread.UseClipboard = 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.PageSize = sheet.RowCount
' 列幅の設定
sheet.Columns(0).Width = 50
sheet.Columns(1).Width = 70
sheet.Columns(2).Width = 130
For i As Integer = 3 To spread.ActiveSheetView.ColumnCount - 1
sheet.Columns(i).Width = 65
Next
' 縦方向の揃え位置を中央に設定
sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle
' 各列のセル型を設定
Dim gnr As New FarPoint.Web.Spread.GeneralCellType()
gnr.FormatString = "#,##0"
sheet.Columns(3, sheet.ColumnCount - 1).CellType = gnr
sheet.Columns(3, sheet.ColumnCount - 1).HorizontalAlign = HorizontalAlign.Right
End Sub
End Class
|
<%@ Page MasterPageFile="~/MasterPage.master" Language="c#" AutoEventWireup="true"
Inherits="clientsynchrocolwidth" CodeFile="clientsynchrocolwidth.aspx.cs" %>
<%@ Register Assembly="FarPoint.Web.SpreadJ" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderPlaceHolder1" Runat="Server">
<script type="text/javascript">
function cwidth1(event) {
if (event == null)
event = window.event;
var s = document.getElementById(spid2);
setcwidth(s, event.col, event.width);
}
function cwidth2(event) {
if (event == null)
event = window.event;
var s = document.getElementById(spid1);
setcwidth(s, event.col, event.width);
}
function setcwidth(spread, col, width) {
spread.SetColWidth(col, width);
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<farpoint:FpSpread ID="FpSpread1" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid"
BorderWidth="1px">
<CommandBar BackColor="Control" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight"
ButtonShadowColor="ControlDark" />
<Sheets>
<farpoint:SheetView SheetName="Sheet1">
</farpoint:SheetView>
</Sheets>
</farpoint:FpSpread>
<br />
<farpoint:FpSpread ID="FpSpread2" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid"
BorderWidth="1px">
<CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight"
ButtonShadowColor="ControlDark" />
<Sheets>
<farpoint:SheetView SheetName="Sheet1">
</farpoint:SheetView>
</Sheets>
</farpoint:FpSpread>
</asp:Content>
|
|