|
シートの非表示
SPREADのシートを簡単に表示・非表示を切り替えることができます。
対象シートのVisibleプロパティを設定することで、シートの表示・非表示を切り替えることができます。
このサンプルでは、ドロップダウンリスト選択時に全2シートの表示・非表示を切り替えています。
| 製品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 |
|
|
ソースコード
別ウィンドウで表示
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
public partial class sheetvisible : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) return;
// シート追加
FarPoint.Web.Spread.SheetView sht = new FarPoint.Web.Spread.SheetView();
FpSpread1.Sheets.Add(sht);
// シート名設定
FpSpread1.Sheets[0].SheetName ="計画シート";
FpSpread1.Sheets[1].SheetName ="実績シート";
// セル型の自動設定を無効化
FpSpread1.Sheets[0].DataAutoCellTypes = false;
FpSpread1.Sheets[1].DataAutoCellTypes = false;
// データ連結
DataSet ds1 = new DataSet();
ds1.ReadXml(MapPath("../App_Data/datapln.xml"));
FpSpread1.Sheets[0].DataSource = ds1;
DataSet ds2 = new DataSet();
ds2.ReadXml(MapPath("../App_Data/datares.xml"));
FpSpread1.Sheets[1].DataSource = ds2;
FarPoint.Web.Spread.SheetView sheet1 = FpSpread1.Sheets[0];
FarPoint.Web.Spread.SheetView sheet2 = FpSpread1.Sheets[1];
// SPREAD設定
FpSpread1.CssClass = "spreadStyle";
FpSpread1.UseClipboard = false;
// シート設定
InitSpread(sheet1);
InitSpread(sheet2);
// クライアント側スクリプトの設定
string clientScript = "<script language=\"JavaScript\">";
clientScript += "function visibleSheet(val)";
clientScript += "{";
clientScript += "var spread = document.getElementById(\"" + FpSpread1.ClientID + "\");";
clientScript += "spread.CallBack(\"Visible.\"+val);";
clientScript += "}";
clientScript += "</script>";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "sheetvisibleScript", clientScript, false);
// シートタブを常に表示
FpSpread1.Tab.TabControlPolicy = FarPoint.Web.Spread.TabControlPolicy.Always;
}
private void InitSpread(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.Columns[0].Width = 45;
sheet.Columns[1].Width = 70;
sheet.Columns[2].Width = 130;
for (int i = 3; i < sheet.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;
}
protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
{
if (e.CommandName.StartsWith("Visible"))
{
string[] strCom = e.CommandName.Split('.');
int val = Convert.ToInt32(strCom[1]);
// 全シート表示
for (int i = 0; i < FpSpread1.Sheets.Count; i++)
{
FpSpread1.Sheets[i].Visible = true;
}
if (val != 99)
{
FpSpread1.Sheets[val].Visible = false;
}
}
}
}
|
Partial Public Class sheetvisible
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
' シート追加
Dim sht As New FarPoint.Web.Spread.SheetView()
FpSpread1.Sheets.Add(sht)
' シート名設定
FpSpread1.Sheets(0).SheetName = "計画シート"
FpSpread1.Sheets(1).SheetName = "実績シート"
' セル型の自動設定を無効化
FpSpread1.Sheets(0).DataAutoCellTypes = False
FpSpread1.Sheets(1).DataAutoCellTypes = False
' データ連結
Dim ds1 As New System.Data.DataSet()
ds1.ReadXml(MapPath("../App_Data/datapln.xml"))
FpSpread1.Sheets(0).DataSource = ds1
Dim ds2 As New System.Data.DataSet()
ds2.ReadXml(MapPath("../App_Data/datares.xml"))
FpSpread1.Sheets(1).DataSource = ds2
Dim sheet1 As FarPoint.Web.Spread.SheetView = FpSpread1.Sheets(0)
Dim sheet2 As FarPoint.Web.Spread.SheetView = FpSpread1.Sheets(1)
' SPREAD設定
FpSpread1.CssClass = "spreadStyle"
FpSpread1.UseClipboard = False
' シート設定
InitSpread(sheet1)
InitSpread(sheet2)
' クライアント側スクリプトの設定
Dim clientScript As String = "<script language=""JavaScript"">"
clientScript += "function visibleSheet(val)"
clientScript += "{"
clientScript += "var spread = document.getElementById(""" + FpSpread1.ClientID & """);"
clientScript += "spread.CallBack(""Visible.""+val);"
clientScript += "}"
clientScript += "</script>"
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "sheetvisibleScript", clientScript, False)
' シートタブを常に表示
FpSpread1.Tab.TabControlPolicy = FarPoint.Web.Spread.TabControlPolicy.Always
End Sub
Private Sub InitSpread(ByVal 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.Columns(0).Width = 45
sheet.Columns(1).Width = 70
sheet.Columns(2).Width = 130
For i As Integer = 3 To sheet.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
Protected Sub FpSpread1_ButtonCommand(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SpreadCommandEventArgs) Handles FpSpread1.ButtonCommand
If e.CommandName.StartsWith("Visible") Then
Dim strCom As String() = e.CommandName.Split("."c)
Dim val As Integer = Convert.ToInt32(strCom(1))
' 全シート表示
For i As Integer = 0 To FpSpread1.Sheets.Count - 1
FpSpread1.Sheets(i).Visible = True
Next
If val <> 99 Then
FpSpread1.Sheets(val).Visible = False
End If
End If
End Sub
End Class
|
<%@ Page MasterPageFile="~/MasterPage.master" Language="c#" AutoEventWireup="true"
Inherits="sheetvisible" CodeFile="sheetvisible.aspx.cs" %>
<%@ Register Assembly="FarPoint.Web.SpreadJ" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" onchange="visibleSheet(this[this.selectedIndex].value);">
<asp:ListItem Value="99">全シート表示</asp:ListItem>
<asp:ListItem Value="0">計画シート非表示</asp:ListItem>
<asp:ListItem Value="1">実績シート非表示</asp:ListItem>
</asp:DropDownList>
<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>
<br />
</asp:Content>
|
|