行・列の固定

FrozenRowCount,FrozenColumnCountに固定する行数、列数を指定することで行・列を固定できます。

このサンプルでは、行は1行目を固定。列は4列目を固定しています。 スクロールさせることで動作を確認できます。
 製品ID製品分類製品名前年比4月5月6月7月8月9月
1月合計:47,17358,63456,68768,89545,44453,666
210001乳製品酪農ミルク
5,5005,0004,5006,0005,5005,000
320001清涼飲料水いよかんドリンク
1,0003,0002,7002,7001,0003,000
420002清涼飲料水ぶどうジュース
3,0003,5004,8004,8003,0003,500
520003清涼飲料水マンゴードリンク
2,0001,0005001,0502,0001,000
630001ビール激辛ビール
5,5008,0008,50010,0005,5008,000
730002ビールモルトビール
3,0003,5002,7804,0003,0003,500
820004清涼飲料水ぶどうの街
500300200700500300
930003ビールオリエントの村
8,0009,5009,5809,0008,0009,500
1040002焼酎吟醸 ほめごろし
6,0007,0009,0009,5006,0007,000
1140003焼酎大吟醸 オリエント
1,0005,0006,0005,0001,0005,000
1240005焼酎麦焼酎 ちこちこ
1,0001,5001,2001,2581,0001,500
1310002乳製品酪農ミルク(低脂肪)
501202380456501202
1430004ビールオリエントの里
963256365554868853
1530005ビールオリエントからの便り
5,4523,3662,5633,3365,5843,333
1630006ビールオリエントの森
103965365885757744
1730007ビールオリエントの町
3,6546,5453,2549,6561,2341,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>