|
結合
SPREADでは、行、列、セル範囲など任意のセルを結合して表示することができます。
任意のセルを基点に、RowSpan プロパティで結合する行数を、ColumnSpan プロパティで結合する列数を指定できます。
ソースコード
別ウィンドウで表示
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class rowcolcell_cellspan : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
return;
}
// SPREADの設定
InitSpread(FpSpread1);
// シートの設定
InitSpreadStyles(FpSpread1.Sheets[0]);
}
private void InitSpread(FarPoint.Web.Spread.FpSpread spread)
{
spread.CssClass = "spreadStyle";
spread.UseClipboard = false;
}
private void InitSpreadStyles(FarPoint.Web.Spread.SheetView sheet)
{
sheet.ColumnCount = 7;
sheet.RowCount = 10;
// フォントサイズの設定
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%");
// 数式の参照スタイルをR1C1形式に設定
sheet.ReferenceStyle = FarPoint.Web.Spread.Model.ReferenceStyle.R1C1;
// 列幅を設定
sheet.Columns[0].Width = 120;
sheet.Columns[5].Width = 120;
// セル間の間隔を1ピクセルに設定
sheet.CellSpacing = 1;
// 縦方向の揃え位置を中央に設定
sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle;
// セル型の設定
FarPoint.Web.Spread.CheckBoxCellType chkcell = new FarPoint.Web.Spread.CheckBoxCellType();
sheet.Columns[4].CellType = chkcell;
sheet.Columns[6].CellType = chkcell;
FarPoint.Web.Spread.CurrencyCellType curcell = new FarPoint.Web.Spread.CurrencyCellType();
sheet.Columns[2].CellType = curcell;
// 列ヘッダの設定
sheet.ColumnHeader.RowCount = 2;
sheet.ColumnHeader.Cells[0, 0].Value = "商品名";
sheet.ColumnHeader.Cells[0, 1].Value = "注文ID";
sheet.ColumnHeader.Cells[1, 1].Value = "注文日";
sheet.ColumnHeader.Cells[0, 2].Value = "単価";
sheet.ColumnHeader.Cells[0, 3].Value = "数量";
sheet.ColumnHeader.Cells[1, 2].Value = "金額";
sheet.ColumnHeader.Cells[0, 4].Value = "注文確認";
sheet.ColumnHeader.Cells[0, 5].Value = "店舗ID";
sheet.ColumnHeader.Cells[1, 5].Value = "店舗名";
sheet.ColumnHeader.Cells[0, 6].Value = "店舗確認";
sheet.ColumnHeader.Cells[0, 0].RowSpan = 2;
sheet.ColumnHeader.Cells[1, 2].ColumnSpan = 2;
sheet.ColumnHeader.Cells[0, 4].RowSpan = 2;
sheet.ColumnHeader.Cells[0, 6].RowSpan = 2;
// テストデータの設定
sheet.Cells[0, 0].Value = "いよかんドリンク";
sheet.Cells[0, 1].Value = "B10101";
sheet.Cells[1, 1].Value = "2009/09/01";
sheet.Cells[0, 2].Value = 800;
sheet.Cells[0, 3].Value = 1;
sheet.Cells[1, 2].Formula = "R[-1]C*R[-1]C[1]";
sheet.Cells[0, 5].Value = "S423";
sheet.Cells[1, 5].Value = "橋龍商事";
sheet.Cells[2, 1].Value = "B10102";
sheet.Cells[3, 1].Value = "2009/09/05";
sheet.Cells[2, 2].Value = 800;
sheet.Cells[2, 3].Value = 4;
sheet.Cells[3, 2].Formula = "R[-1]C*R[-1]C[1]";
sheet.Cells[2, 5].Value = "S357";
sheet.Cells[3, 5].Value = "グレープストア";
sheet.Cells[4, 1].Value = "B10103";
sheet.Cells[5, 1].Value = "2009/09/06";
sheet.Cells[4, 2].Value = 800;
sheet.Cells[4, 3].Value = 2;
sheet.Cells[5, 2].Formula = "R[-1]C*R[-1]C[1]";
sheet.Cells[4, 5].Value = "S341";
sheet.Cells[5, 5].Value = "丘野ソフト商会";
sheet.Cells[6, 0].Value = "麦焼酎 ちこちこ";
sheet.Cells[6, 1].Value = "C10101";
sheet.Cells[7, 1].Value = "2009/09/03";
sheet.Cells[6, 2].Value = 4800;
sheet.Cells[6, 3].Value = 2;
sheet.Cells[7, 2].Formula = "R[-1]C*R[-1]C[1]";
sheet.Cells[6, 5].Value = "S201";
sheet.Cells[7, 5].Value = "グレープタウン商事";
sheet.Cells[8, 1].Value = "C10102";
sheet.Cells[9, 1].Value = "2009/09/04";
sheet.Cells[8, 2].Value = 4800;
sheet.Cells[8, 3].Value = 5;
sheet.Cells[9, 2].Formula = "R[-1]C*R[-1]C[1]";
sheet.Cells[8, 5].Value = "S357";
sheet.Cells[9, 5].Value = "グレープストア";
// セルの結合
sheet.Cells[0, 0].RowSpan = 6;
sheet.Cells[1, 2].ColumnSpan = 2;
sheet.Cells[0, 4].RowSpan = 2;
sheet.Cells[0, 6].RowSpan = 2;
sheet.Cells[3, 2].ColumnSpan = 2;
sheet.Cells[2, 4].RowSpan = 2;
sheet.Cells[2, 6].RowSpan = 2;
sheet.Cells[5, 2].ColumnSpan = 2;
sheet.Cells[4, 4].RowSpan = 2;
sheet.Cells[4, 6].RowSpan = 2;
sheet.Cells[6, 0].RowSpan = 4;
sheet.Cells[7, 2].ColumnSpan = 2;
sheet.Cells[6, 4].RowSpan = 2;
sheet.Cells[6, 6].RowSpan = 2;
sheet.Cells[9, 2].ColumnSpan = 2;
sheet.Cells[8, 4].RowSpan = 2;
sheet.Cells[8, 6].RowSpan = 2;
sheet.DefaultStyle.HorizontalAlign = HorizontalAlign.Center;
}
}
|
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Partial Public Class rowcolcell_cellspan
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
' SPREADの設定
InitSpread(FpSpread1)
' シートの設定
InitSpreadStyles(FpSpread1.Sheets(0))
End Sub
Private Sub InitSpread(ByVal spread As FarPoint.Web.Spread.FpSpread)
spread.CssClass = "spreadStyle"
spread.UseClipboard = False
End Sub
Private Sub InitSpreadStyles(ByVal sheet As FarPoint.Web.Spread.SheetView)
sheet.ColumnCount = 7
sheet.RowCount = 10
' フォントサイズの設定
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%")
' 数式の参照スタイルをR1C1形式に設定
sheet.ReferenceStyle = FarPoint.Web.Spread.Model.ReferenceStyle.R1C1
' 列幅を設定
sheet.Columns(0).Width = 120
sheet.Columns(5).Width = 120
' セル間の間隔を1ピクセルに設定
sheet.CellSpacing = 1
' 縦方向の揃え位置を中央に設定
sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle
' セル型の設定
Dim chkcell As New FarPoint.Web.Spread.CheckBoxCellType()
sheet.Columns(4).CellType = chkcell
sheet.Columns(6).CellType = chkcell
Dim curcell As New FarPoint.Web.Spread.CurrencyCellType()
sheet.Columns(2).CellType = curcell
' 列ヘッダの設定
sheet.ColumnHeader.RowCount = 2
sheet.ColumnHeader.Cells(0, 0).Value = "商品名"
sheet.ColumnHeader.Cells(0, 1).Value = "注文ID"
sheet.ColumnHeader.Cells(1, 1).Value = "注文日"
sheet.ColumnHeader.Cells(0, 2).Value = "単価"
sheet.ColumnHeader.Cells(0, 3).Value = "数量"
sheet.ColumnHeader.Cells(1, 2).Value = "金額"
sheet.ColumnHeader.Cells(0, 4).Value = "注文確認"
sheet.ColumnHeader.Cells(0, 5).Value = "店舗ID"
sheet.ColumnHeader.Cells(1, 5).Value = "店舗名"
sheet.ColumnHeader.Cells(0, 6).Value = "店舗確認"
sheet.ColumnHeader.Cells(0, 0).RowSpan = 2
sheet.ColumnHeader.Cells(1, 2).ColumnSpan = 2
sheet.ColumnHeader.Cells(0, 4).RowSpan = 2
sheet.ColumnHeader.Cells(0, 6).RowSpan = 2
' テストデータの設定
sheet.Cells(0, 0).Value = "いよかんドリンク"
sheet.Cells(0, 1).Value = "B10101"
sheet.Cells(1, 1).Value = "2009/09/01"
sheet.Cells(0, 2).Value = 800
sheet.Cells(0, 3).Value = 1
sheet.Cells(1, 2).Formula = "R[-1]C*R[-1]C[1]"
sheet.Cells(0, 5).Value = "S423"
sheet.Cells(1, 5).Value = "橋龍商事"
sheet.Cells(2, 1).Value = "B10102"
sheet.Cells(3, 1).Value = "2009/09/05"
sheet.Cells(2, 2).Value = 800
sheet.Cells(2, 3).Value = 4
sheet.Cells(3, 2).Formula = "R[-1]C*R[-1]C[1]"
sheet.Cells(2, 5).Value = "S357"
sheet.Cells(3, 5).Value = "グレープストア"
sheet.Cells(4, 1).Value = "B10103"
sheet.Cells(5, 1).Value = "2009/09/06"
sheet.Cells(4, 2).Value = 800
sheet.Cells(4, 3).Value = 2
sheet.Cells(5, 2).Formula = "R[-1]C*R[-1]C[1]"
sheet.Cells(4, 5).Value = "S341"
sheet.Cells(5, 5).Value = "丘野ソフト商会"
sheet.Cells(6, 0).Value = "麦焼酎 ちこちこ"
sheet.Cells(6, 1).Value = "C10101"
sheet.Cells(7, 1).Value = "2009/09/03"
sheet.Cells(6, 2).Value = 4800
sheet.Cells(6, 3).Value = 2
sheet.Cells(7, 2).Formula = "R[-1]C*R[-1]C[1]"
sheet.Cells(6, 5).Value = "S201"
sheet.Cells(7, 5).Value = "グレープタウン商事"
sheet.Cells(8, 1).Value = "C10102"
sheet.Cells(9, 1).Value = "2009/09/04"
sheet.Cells(8, 2).Value = 4800
sheet.Cells(8, 3).Value = 5
sheet.Cells(9, 2).Formula = "R[-1]C*R[-1]C[1]"
sheet.Cells(8, 5).Value = "S357"
sheet.Cells(9, 5).Value = "グレープストア"
' セルの結合
sheet.Cells(0, 0).RowSpan = 6
sheet.Cells(1, 2).ColumnSpan = 2
sheet.Cells(0, 4).RowSpan = 2
sheet.Cells(0, 6).RowSpan = 2
sheet.Cells(3, 2).ColumnSpan = 2
sheet.Cells(2, 4).RowSpan = 2
sheet.Cells(2, 6).RowSpan = 2
sheet.Cells(5, 2).ColumnSpan = 2
sheet.Cells(4, 4).RowSpan = 2
sheet.Cells(4, 6).RowSpan = 2
sheet.Cells(6, 0).RowSpan = 4
sheet.Cells(7, 2).ColumnSpan = 2
sheet.Cells(6, 4).RowSpan = 2
sheet.Cells(6, 6).RowSpan = 2
sheet.Cells(9, 2).ColumnSpan = 2
sheet.Cells(8, 4).RowSpan = 2
sheet.Cells(8, 6).RowSpan = 2
sheet.DefaultStyle.HorizontalAlign = HorizontalAlign.Center
End Sub
End Class
|
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="cellspan.aspx.cs" Inherits="rowcolcell_cellspan" %>
<%@ Register Assembly="FarPoint.Web.SpreadJ" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderPlaceHolder1" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" 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>
|
|