ナビゲーション リンクのスキップ
 新機能 の展開 新機能
 InputMan連携 の展開 InputMan連携
 マルチタッチ機能 の展開 マルチタッチ機能
 セル、行、列、ヘッダ の展開 セル、行、列、ヘッダ
 シート の展開 シート
 スタイル の展開 スタイル
 選択 の展開 選択
 セル型 の展開 セル型
 編集 の展開 編集
 ソート の展開 ソート
 フィルタリング の展開 フィルタリング
 グループ化 の展開 グループ化
 ページング の展開 ページング
 スクロール の展開 スクロール
 データ連結 の縮小 データ連結
 階層表示 の展開 階層表示
 コマンドバー の展開 コマンドバー
 チャート の展開 チャート
 数式 の展開 数式
 インポート/エクスポート の展開 インポート/エクスポート
 クライアント側スクリプト の展開 クライアント側スクリプト

特定の列だけを連結

FpSpreadクラスのDataSourceプロパティに対してデータセットを設定した場合、 デフォルトでは全てのフィールドが自動的に連結されます。

ただし、ColumnsクラスのDataFieldプロパティを使用すると、表示フィールドの位置(順番)を変更したり、ある特定のフィールドのみを連結することができます。

このサンプルでSPREADと連結しているテーブルは、1テーブルに月単位に「計画」列と「実績」列を保持しています。
例)「4月計画」、「4月実績」、「5月計画」、「5月実績」...

「計画データのみを連結」ボタンを押下すると、テーブル上の「計画」列のみをSPREADと連結します。
「実績データのみを連結」ボタンを押下すると、テーブル上の「実績」列のみをSPREADと連結します。
「全データを連結」ボタンを押下すると、テーブル上の全ての列をSPREADと連結します。
 製品ID製品分類製品名4月計画4月実績5月計画5月実績6月計画6月実績7月計画7月実績8月計画8月実績9月計画9月実績10月計画10月実績11月計画11月実績12月計画12月実績1月計画1月実績2月計画2月実績3月計画3月実績
110001乳製品酪農ミルク5,5005,6005,0005,1004,5004,6006,0006,1005,5005,6005,0005,1004,5004,6006,0006,1005,5005,6005,0005,1004,5004,6006,0006,100
220001清涼飲料水いよかんドリンク1,0001,1003,0003,1002,7002,8002,7002,8001,0001,1003,0003,1002,7002,8002,7002,8001,0001,1003,0003,1002,7002,8002,7002,800
320002清涼飲料水ぶどうジュース3,0003,1003,5003,6004,8004,9004,8004,9003,0003,1003,5003,6004,8004,9004,8004,9003,0003,1003,5003,6004,8004,9004,8004,900
420003清涼飲料水マンゴードリンク2,0002,1001,0001,1005006001,0501,1502,0002,1001,0001,1005006001,0501,1502,0002,1001,0001,1005006001,0501,150
530001ビール激辛ビール5,5005,6008,0008,1008,5008,60010,00010,1005,5005,6008,0008,1008,5008,60010,00010,1005,5005,6008,0008,1008,5008,60010,00010,100
630002ビールモルトビール3,0003,1003,5003,6002,7802,8804,0004,1003,0003,1003,5003,6002,7802,8804,0004,1003,0003,1003,5003,6002,7802,8804,0004,100
720004清涼飲料水ぶどうの街500600300400200300700800500600300400200300700800500600300400200300700800
830003ビールオリエントの村8,0008,1009,5009,6009,5809,6809,0009,1008,0008,1009,5009,6009,5809,6809,0009,1008,0008,1009,5009,6009,5809,6809,0009,100
940002焼酎吟醸 ほめごろし6,0006,1007,0007,1009,0009,1009,5009,6006,0006,1007,0007,1009,0009,1009,5009,6006,0006,1007,0007,1009,0009,1009,5009,600
1040003焼酎大吟醸 オリエント1,0001,1005,0005,1006,0006,1005,0005,1001,0001,1005,0005,1006,0006,1005,0005,1001,0001,1005,0005,1006,0006,1005,0005,100
1140005焼酎麦焼酎 ちこちこ1,0001,1001,5001,6001,2001,3001,2581,3581,0001,1001,5001,6001,2001,3001,2581,3581,0001,1001,5001,6001,2001,3001,2581,358
1210002乳製品酪農ミルク(低脂肪)501601202302380480456556501601202302380480456556501601202302380480456556

ソースコード

別ウィンドウで表示
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;

public partial class fieldbinding : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack) return;

        // データ連結
        BindSpread(0);
        
        // SPREAD初期化
        InitSpread(FpSpread1.Sheets[0]);

        // クライアント側スクリプトの設定
        string clientScript = "<script language=\"JavaScript\">";
        clientScript += "function bindschedule()";
        clientScript += "{";
        clientScript += "var spread = document.getElementById(\"" + FpSpread1.ClientID + "\");";
        clientScript += "spread.CallBack(\"bindschedule\");";
        clientScript += "}";
        clientScript += "function bindresult()";
        clientScript += "{";
        clientScript += "var spread = document.getElementById(\"" + FpSpread1.ClientID + "\");";
        clientScript += "spread.CallBack(\"bindresult\");";
        clientScript += "}";
        clientScript += "function bindall()";
        clientScript += "{";
        clientScript += "var spread = document.getElementById(\"" + FpSpread1.ClientID + "\");";
        clientScript += "spread.CallBack(\"bindall\");";
        clientScript += "}";
        clientScript += "</script>";

        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "fieldbindingScript", clientScript, false);
    }

    private void InitSpread(FarPoint.Web.Spread.SheetView sheet)
    {
        // SPREAD設定
        sheet.FpSpread.CommandBar.Visible = false;
        sheet.FpSpread.CssClass = "spreadStyle";
        sheet.FpSpread.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 = 140;

        for (int i = 3; i < FpSpread1.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, FpSpread1.ActiveSheetView.ColumnCount -1].CellType = gnr;
        sheet.Columns[3, FpSpread1.ActiveSheetView.ColumnCount - 1].HorizontalAlign = HorizontalAlign.Right;
    }

    private void BindSpread(int dataflg)
    {
        // リセット
        FarPoint.Web.Spread.SheetView sht = new FarPoint.Web.Spread.SheetView();
        sht = FpSpread1.ActiveSheetView;
        FpSpread1.Reset();
        FpSpread1.Sheets.Add(sht);

        // セル型の自動設定を無効化
        FpSpread1.ActiveSheetView.DataAutoCellTypes = false;

        DataSet ds = new DataSet();
        ds.ReadXml(MapPath("../App_Data/databind.xml"));

        if (dataflg == 0)
        {
            FpSpread1.ActiveSheetView.AutoGenerateColumns = true;
            FpSpread1.ActiveSheetView.DataSource = ds;
        }
        else
        {
            // 連結時の列自動生成を無効
            FpSpread1.ActiveSheetView.AutoGenerateColumns = false;
            FpSpread1.ActiveSheetView.ColumnCount = 15;

            FpSpread1.ActiveSheetView.DataSource = ds;

            FpSpread1.ActiveSheetView.Columns[0].DataField = "製品ID";
            FpSpread1.ActiveSheetView.Columns[1].DataField = "製品分類";
            FpSpread1.ActiveSheetView.Columns[2].DataField = "製品名";

            if (dataflg == 1)
            {
                FpSpread1.ActiveSheetView.Columns[3].DataField = "4月計画";
                FpSpread1.ActiveSheetView.Columns[4].DataField = "5月計画";
                FpSpread1.ActiveSheetView.Columns[5].DataField = "6月計画";
                FpSpread1.ActiveSheetView.Columns[6].DataField = "7月計画";
                FpSpread1.ActiveSheetView.Columns[7].DataField = "8月計画";
                FpSpread1.ActiveSheetView.Columns[8].DataField = "9月計画";
                FpSpread1.ActiveSheetView.Columns[9].DataField = "10月計画";
                FpSpread1.ActiveSheetView.Columns[10].DataField = "11月計画";
                FpSpread1.ActiveSheetView.Columns[11].DataField = "12月計画";
                FpSpread1.ActiveSheetView.Columns[12].DataField = "1月計画";
                FpSpread1.ActiveSheetView.Columns[13].DataField = "2月計画";
                FpSpread1.ActiveSheetView.Columns[14].DataField = "3月計画";
            }
            else
            {
                FpSpread1.ActiveSheetView.Columns[3].DataField = "4月実績";
                FpSpread1.ActiveSheetView.Columns[4].DataField = "5月実績";
                FpSpread1.ActiveSheetView.Columns[5].DataField = "6月実績";
                FpSpread1.ActiveSheetView.Columns[6].DataField = "7月実績";
                FpSpread1.ActiveSheetView.Columns[7].DataField = "8月実績";
                FpSpread1.ActiveSheetView.Columns[8].DataField = "9月実績";
                FpSpread1.ActiveSheetView.Columns[9].DataField = "10月実績";
                FpSpread1.ActiveSheetView.Columns[10].DataField = "11月実績";
                FpSpread1.ActiveSheetView.Columns[11].DataField = "12月実績";
                FpSpread1.ActiveSheetView.Columns[12].DataField = "1月実績";
                FpSpread1.ActiveSheetView.Columns[13].DataField = "2月実績";
                FpSpread1.ActiveSheetView.Columns[14].DataField = "3月実績";
            }
            FpSpread1.DataBind();
        }
    }

    protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
    {
        if (e.CommandName == "bindschedule")
        {
            // 計画データ連結
            BindSpread(1);

            FarPoint.Web.Spread.SheetView sheet = FpSpread1.Sheets[0];
            
            // SPREAD初期化
            InitSpread(sheet);  
        }
        else if (e.CommandName == "bindresult")
        {
            // 実績データ連結
            BindSpread(2);

            FarPoint.Web.Spread.SheetView sheet = FpSpread1.Sheets[0];
            
            // SPREAD初期化
            InitSpread(sheet);
        }
        else if (e.CommandName == "bindall")
        {
            // 全データ連結
            BindSpread(0);

            FarPoint.Web.Spread.SheetView sheet = FpSpread1.Sheets[0];
            
            // SPREAD初期化
            InitSpread(sheet);
        }
    }
}

Partial Public Class fieldbinding
    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

        ' データ連結
        BindSpread(0)

        ' SPREAD初期化
        InitSpread(FpSpread1.Sheets(0))

        ' クライアント側スクリプトの設定
        Dim clientScript As String = "<script language=""JavaScript"">"
        clientScript += "function bindschedule()"
        clientScript += "{"
        clientScript += "var spread = document.getElementById(""" + FpSpread1.ClientID & """);"
        clientScript += "spread.CallBack(""bindschedule"");"
        clientScript += "}"
        clientScript += "function bindresult()"
        clientScript += "{"
        clientScript += "var spread = document.getElementById(""" + FpSpread1.ClientID & """);"
        clientScript += "spread.CallBack(""bindresult"");"
        clientScript += "}"
        clientScript += "function bindall()"
        clientScript += "{"
        clientScript += "var spread = document.getElementById(""" + FpSpread1.ClientID & """);"
        clientScript += "spread.CallBack(""bindall"");"
        clientScript += "}"
        clientScript += "</script>"

        ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "fieldbindingScript", clientScript, False)
    End Sub

    Private Sub InitSpread(ByVal sheet As FarPoint.Web.Spread.SheetView)
        ' SPREAD設定
        sheet.FpSpread.CommandBar.Visible = False
        sheet.FpSpread.CssClass = "spreadStyle"
        sheet.FpSpread.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 = 140

        For i As Integer = 3 To FpSpread1.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, FpSpread1.ActiveSheetView.ColumnCount - 1).CellType = gnr
        sheet.Columns(3, FpSpread1.ActiveSheetView.ColumnCount - 1).HorizontalAlign = HorizontalAlign.Right
    End Sub

    Private Sub BindSpread(ByVal dataflg As Integer)
        ' リセット
        Dim sht As New FarPoint.Web.Spread.SheetView()
        sht = FpSpread1.ActiveSheetView
        FpSpread1.Reset()
        FpSpread1.Sheets.Add(sht)

        ' セル型の自動設定を無効化
        FpSpread1.ActiveSheetView.DataAutoCellTypes = False

        Dim ds As New System.Data.DataSet()
        ds.ReadXml(MapPath("../App_Data/databind.xml"))

        If dataflg = 0 Then
            FpSpread1.ActiveSheetView.AutoGenerateColumns = True
            FpSpread1.ActiveSheetView.DataSource = ds
        Else
            ' 連結時の列自動生成を無効
            FpSpread1.ActiveSheetView.AutoGenerateColumns = False
            FpSpread1.ActiveSheetView.ColumnCount = 15

            FpSpread1.ActiveSheetView.DataSource = ds

            FpSpread1.ActiveSheetView.Columns(0).DataField = "製品ID"
            FpSpread1.ActiveSheetView.Columns(1).DataField = "製品分類"
            FpSpread1.ActiveSheetView.Columns(2).DataField = "製品名"

            If dataflg = 1 Then
                FpSpread1.ActiveSheetView.Columns(3).DataField = "4月計画"
                FpSpread1.ActiveSheetView.Columns(4).DataField = "5月計画"
                FpSpread1.ActiveSheetView.Columns(5).DataField = "6月計画"
                FpSpread1.ActiveSheetView.Columns(6).DataField = "7月計画"
                FpSpread1.ActiveSheetView.Columns(7).DataField = "8月計画"
                FpSpread1.ActiveSheetView.Columns(8).DataField = "9月計画"
                FpSpread1.ActiveSheetView.Columns(9).DataField = "10月計画"
                FpSpread1.ActiveSheetView.Columns(10).DataField = "11月計画"
                FpSpread1.ActiveSheetView.Columns(11).DataField = "12月計画"
                FpSpread1.ActiveSheetView.Columns(12).DataField = "1月計画"
                FpSpread1.ActiveSheetView.Columns(13).DataField = "2月計画"
                FpSpread1.ActiveSheetView.Columns(14).DataField = "3月計画"
            Else
                FpSpread1.ActiveSheetView.Columns(3).DataField = "4月実績"
                FpSpread1.ActiveSheetView.Columns(4).DataField = "5月実績"
                FpSpread1.ActiveSheetView.Columns(5).DataField = "6月実績"
                FpSpread1.ActiveSheetView.Columns(6).DataField = "7月実績"
                FpSpread1.ActiveSheetView.Columns(7).DataField = "8月実績"
                FpSpread1.ActiveSheetView.Columns(8).DataField = "9月実績"
                FpSpread1.ActiveSheetView.Columns(9).DataField = "10月実績"
                FpSpread1.ActiveSheetView.Columns(10).DataField = "11月実績"
                FpSpread1.ActiveSheetView.Columns(11).DataField = "12月実績"
                FpSpread1.ActiveSheetView.Columns(12).DataField = "1月実績"
                FpSpread1.ActiveSheetView.Columns(13).DataField = "2月実績"
                FpSpread1.ActiveSheetView.Columns(14).DataField = "3月実績"
            End If
            FpSpread1.DataBind()
        End If
    End Sub

    Protected Sub FpSpread1_ButtonCommand(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SpreadCommandEventArgs) Handles FpSpread1.ButtonCommand
        If e.CommandName = "bindschedule" Then
            ' 計画データ連結
            BindSpread(1)

            Dim sheet As FarPoint.Web.Spread.SheetView = FpSpread1.Sheets(0)

            ' SPREAD初期化
            InitSpread(sheet)
        ElseIf e.CommandName = "bindresult" Then
            ' 実績データ連結
            BindSpread(2)

            Dim sheet As FarPoint.Web.Spread.SheetView = FpSpread1.Sheets(0)

            ' SPREAD初期化
            InitSpread(sheet)
        ElseIf e.CommandName = "bindall" Then
            ' 全データ連結
            BindSpread(0)

            Dim sheet As FarPoint.Web.Spread.SheetView = FpSpread1.Sheets(0)

            ' SPREAD初期化
            InitSpread(sheet)
        End If
    End Sub
End Class
<%@ Page MasterPageFile="~/MasterPage.master" Language="c#" AutoEventWireup="true" 
         Inherits="fieldbinding" CodeFile="fieldbinding.aspx.cs" %>

<%@ Register Assembly="FarPoint.Web.SpreadJ" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <input id="Button1" type="button" value="計画データのみを連結" onclick="bindschedule();" style="width: 160px;" />
    <input id="Button2" type="button" value="実績データのみを連結" onclick="bindresult();" style="width: 160px;" />
    <input id="Button3" type="button" value="全データを連結" onclick="bindall();" style="width: 160px;" />
    <farpoint:FpSpread ID="FpSpread1" runat="server" 
        onbuttoncommand="FpSpread1_ButtonCommand">
        <CommandBar BackColor="Control" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight"
            ButtonShadowColor="ControlDark" />
        <Sheets>
            <farpoint:SheetView SheetName="Sheet1">
            </farpoint:SheetView>
        </Sheets>
    </farpoint:FpSpread>
</asp:Content>