|
行・列の固定
FrozenRowCount,FrozenColumnCountに固定する行数、列数を指定することで行・列を固定できます。
このサンプルでは、行は1行目を固定。列は4列目を固定しています。
スクロールさせることで動作を確認できます。
| 製品ID | 製品分類 | 製品名 | 前年比 | 4月 | 5月 | 6月 | 7月 | 8月 | 9月 |
1 | 月合計: | 47,173 | 58,634 | 56,687 | 68,895 | 45,444 | 53,666 |
2 | 10001 | 乳製品 | 酪農ミルク | | 5,500 | 5,000 | 4,500 | 6,000 | 5,500 | 5,000 |
3 | 20001 | 清涼飲料水 | いよかんドリンク | | 1,000 | 3,000 | 2,700 | 2,700 | 1,000 | 3,000 |
4 | 20002 | 清涼飲料水 | ぶどうジュース | | 3,000 | 3,500 | 4,800 | 4,800 | 3,000 | 3,500 |
5 | 20003 | 清涼飲料水 | マンゴードリンク | | 2,000 | 1,000 | 500 | 1,050 | 2,000 | 1,000 |
6 | 30001 | ビール | 激辛ビール | | 5,500 | 8,000 | 8,500 | 10,000 | 5,500 | 8,000 |
7 | 30002 | ビール | モルトビール | | 3,000 | 3,500 | 2,780 | 4,000 | 3,000 | 3,500 |
8 | 20004 | 清涼飲料水 | ぶどうの街 | | 500 | 300 | 200 | 700 | 500 | 300 |
9 | 30003 | ビール | オリエントの村 | | 8,000 | 9,500 | 9,580 | 9,000 | 8,000 | 9,500 |
10 | 40002 | 焼酎 | 吟醸 ほめごろし | | 6,000 | 7,000 | 9,000 | 9,500 | 6,000 | 7,000 |
11 | 40003 | 焼酎 | 大吟醸 オリエント | | 1,000 | 5,000 | 6,000 | 5,000 | 1,000 | 5,000 |
12 | 40005 | 焼酎 | 麦焼酎 ちこちこ | | 1,000 | 1,500 | 1,200 | 1,258 | 1,000 | 1,500 |
13 | 10002 | 乳製品 | 酪農ミルク(低脂肪) | | 501 | 202 | 380 | 456 | 501 | 202 |
14 | 30004 | ビール | オリエントの里 | | 963 | 256 | 365 | 554 | 868 | 853 |
15 | 30005 | ビール | オリエントからの便り | | 5,452 | 3,366 | 2,563 | 3,336 | 5,584 | 3,333 |
16 | 30006 | ビール | オリエントの森 | | 103 | 965 | 365 | 885 | 757 | 744 |
17 | 30007 | ビール | オリエントの町 | | 3,654 | 6,545 | 3,254 | 9,656 | 1,234 | 1,234 |
|
ソースコード
別ウィンドウで表示
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
public partial class frozenrowcol : 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]);
}
private void InitSpread(FarPoint.Web.Spread.SheetView sheet)
{
int i;
// SPREAD設定
FpSpread1.CommandBar.Visible = false;
FpSpread1.CssClass = "spreadStyle";
FpSpread1.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 = 45;
sheet.Columns[1].Width = 85;
sheet.Columns[2].Width = 160;
sheet.Columns[3].Width = 50;
sheet.Columns[4].Width = 70;
sheet.Columns[5].Width = 70;
sheet.Columns[6].Width = 70;
sheet.Columns[7].Width = 70;
sheet.Columns[8].Width = 70;
sheet.Columns[9].Width = 70;
// 縦方向の揃え位置を中央に設定
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].VerticalAlign = VerticalAlign.Middle;
// 非連結行追加
sheet.AddUnboundRows(0, 1);
sheet.AddSpanCell(0, 0, 1, 4);
sheet.Cells[0, 0].Value = "月合計:";
sheet.Cells[0, 0].VerticalAlign = VerticalAlign.Middle;
sheet.Cells[0, 0].HorizontalAlign = HorizontalAlign.Right;
// 行・列を固定
sheet.FrozenRowCount = 1;
sheet.FrozenColumnCount = 4;
// 数式の設定
sheet.ReferenceStyle = FarPoint.Web.Spread.Model.ReferenceStyle.R1C1;
for (i = 4; i < sheet.ColumnCount; i++)
{
sheet.Cells[0, i].Formula = "SUM(R[1]C:R[16]C)";
}
// イメージ型セルの設定
FarPoint.Web.Spread.ImageCellType icUp = new FarPoint.Web.Spread.ImageCellType();
icUp.ImageUrl = "../images/uparrow.png";
FarPoint.Web.Spread.ImageCellType icSmallUp = new FarPoint.Web.Spread.ImageCellType();
icSmallUp.ImageUrl = "../images/smalluparrow.png";
FarPoint.Web.Spread.ImageCellType icDown = new FarPoint.Web.Spread.ImageCellType();
icDown.ImageUrl = "../images/downarrow.png";
FarPoint.Web.Spread.ImageCellType icSmallDown = new FarPoint.Web.Spread.ImageCellType();
icSmallDown.ImageUrl = "../images/smalldownarrow.png";
for (i = 1; i < sheet.RowCount; i++)
{
if (sheet.Cells[i, 3].Value.ToString() == "◎")
{
sheet.Cells[i, 3].CellType = icUp;
}
else if (sheet.Cells[i, 3].Value.ToString() == "○")
{
sheet.Cells[i, 3].CellType = icSmallUp;
}
else if (sheet.Cells[i, 3].Value.ToString() == "△")
{
sheet.Cells[i, 3].CellType = icSmallDown;
}
else if (sheet.Cells[i, 3].Value.ToString() == "×")
{
sheet.Cells[i, 3].CellType = icDown;
}
sheet.Cells[i, 3].Value = "";
}
}
}
|
Partial Public Class frozenrowcol
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))
End Sub
Private Sub InitSpread(ByVal sheet As FarPoint.Web.Spread.SheetView)
Dim i As Integer
' SPREAD設定
FpSpread1.CommandBar.Visible = False
FpSpread1.CssClass = "spreadStyle"
FpSpread1.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 = 45
sheet.Columns(1).Width = 85
sheet.Columns(2).Width = 160
sheet.Columns(3).Width = 50
sheet.Columns(4).Width = 70
sheet.Columns(5).Width = 70
sheet.Columns(6).Width = 70
sheet.Columns(7).Width = 70
sheet.Columns(8).Width = 70
sheet.Columns(9).Width = 70
' 縦方向の揃え位置を中央に設定
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).VerticalAlign = VerticalAlign.Middle
' 非連結行追加
sheet.AddUnboundRows(0, 1)
sheet.AddSpanCell(0, 0, 1, 4)
sheet.Cells(0, 0).Value = "月合計:"
sheet.Cells(0, 0).VerticalAlign = VerticalAlign.Middle
sheet.Cells(0, 0).HorizontalAlign = HorizontalAlign.Right
' 行・列を固定
sheet.FrozenRowCount = 1
sheet.FrozenColumnCount = 4
' 数式の設定
sheet.ReferenceStyle = FarPoint.Web.Spread.Model.ReferenceStyle.R1C1
For i = 4 To sheet.ColumnCount - 1
sheet.Cells(0, i).Formula = "SUM(R[1]C:R[16]C)"
Next
' イメージ型セルの設定
Dim icUp As New FarPoint.Web.Spread.ImageCellType()
icUp.ImageUrl = "../images/uparrow.png"
Dim icSmallUp As New FarPoint.Web.Spread.ImageCellType()
icSmallUp.ImageUrl = "../images/smalluparrow.png"
Dim icDown As New FarPoint.Web.Spread.ImageCellType()
icDown.ImageUrl = "../images/downarrow.png"
Dim icSmallDown As New FarPoint.Web.Spread.ImageCellType()
icSmallDown.ImageUrl = "../images/smalldownarrow.png"
For i = 1 To sheet.RowCount - 1
If sheet.Cells(i, 3).Value.ToString() = "◎" Then
sheet.Cells(i, 3).CellType = icUp
ElseIf sheet.Cells(i, 3).Value.ToString() = "○" Then
sheet.Cells(i, 3).CellType = icSmallUp
ElseIf sheet.Cells(i, 3).Value.ToString() = "△" Then
sheet.Cells(i, 3).CellType = icSmallDown
ElseIf sheet.Cells(i, 3).Value.ToString() = "×" Then
sheet.Cells(i, 3).CellType = icDown
End If
sheet.Cells(i, 3).Value = ""
Next
End Sub
End Class
|
<%@ Page MasterPageFile="~/MasterPage.master" Language="c#" AutoEventWireup="true"
Inherits="frozenrowcol" CodeFile="frozenrowcol.aspx.cs" %>
<%@ Register Assembly="FarPoint.Web.SpreadJ" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<farpoint:FpSpread ID="FpSpread1" 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>
|
|