MESCIUS SPREAD for ASP.NET 10.0J サンプルコード集
1レコードを複数行にレイアウトする

SheetViewクラスのLayoutModeをRowTemplateLayoutModeに設定し、WorksheetTemplateプロパティにレイアウトを定義します。

実行例:

1レコードを2行にレイアウトしています。

FpSpread1.DataSource = new OrderList();
SheetView sheet = FpSpread1.Sheets[0];
//集計列を追加します
int lastCol = sheet.ColumnCount;
sheet.AddColumns(lastCol, 2);
sheet.Columns[lastCol].Formula = "E1";
sheet.Columns[lastCol + 1].Formula = "D1*E1";
//列ラベルを設定します
List<string> colLabels = new List<string>();
colLabels.Add("区分");
colLabels.Add("コード");
colLabels.Add("商部");
colLabels.Add("数量");
colLabels.Add("単価");
colLabels.Add("備考");
colLabels.Add("商品名");
colLabels.Add("単位");
colLabels.Add("原価");
colLabels.Add("定価");
colLabels.Add("金額");
for(int i = 0; i < lastCol + 2; i++)
{
    sheet.Columns[i].Label = colLabels[i];
}
//テンプレートを作成します
sheet.LayoutMode = SheetView.LayoutModeType.RowTemplateLayoutMode;
WorksheetTemplate template = sheet.WorksheetTemplate;
//レイアウトを作成します(列数、列幅)
template.LayoutColumns.Count = 8;
template.LayoutColumns[0].Width = 50; //区分           
template.LayoutColumns[1].Width = 200; //コード/商品名
template.LayoutColumns[2].Width = 30; //商部
template.LayoutColumns[3].Width = 90; //定価
template.LayoutColumns[4].Width = 30; //数量/単位
template.LayoutColumns[5].Width = 90; //単価/原価
template.LayoutColumns[6].Width = 90; //金額
template.LayoutColumns[7].Width = 100; //備考
//レイアウトを作成します(行数、行の高さ、セル結合)
template.RowTemplate.RowCount = 2;
template.RowTemplate.LayoutRows[0, 1].Height = 20;
template.RowTemplate.LayoutCells[0, 0].RowSpan = 2;
template.RowTemplate.LayoutCells[0, 2].RowSpan = 2;
template.RowTemplate.LayoutCells[0, 7].RowSpan = 2;
//テンプレートのセルにデータを割り当てます(1行目)
template.LayoutCells[0, 0].DataIndex = colLabels.IndexOf("区分");
template.LayoutCells[0, 1].DataIndex = colLabels.IndexOf("コード");
template.LayoutCells[0, 2].DataIndex = colLabels.IndexOf("商部");
template.LayoutCells[0, 3].DataIndex = colLabels.IndexOf("定価");
template.LayoutCells[0, 4].DataIndex = colLabels.IndexOf("数量");
template.LayoutCells[0, 5].DataIndex = colLabels.IndexOf("単価");
template.LayoutCells[0, 6].DataIndex = colLabels.IndexOf("金額");
template.LayoutCells[0, 7].DataIndex = colLabels.IndexOf("備考");
//テンプレートのセルにデータを割り当てます(2行目)
template.LayoutCells[1, 1].DataIndex = colLabels.IndexOf("商品名");
template.LayoutCells[1, 4].DataIndex = colLabels.IndexOf("単位");
template.LayoutCells[1, 5].DataIndex = colLabels.IndexOf("原価");
FpSpread1.ClientAutoSize = true;
FpSpread1.DataSource = New OrderList()
Dim sheet As SheetView = FpSpread1.Sheets(0)
'集計列を追加します
Dim lastCol As Integer = sheet.ColumnCount
sheet.AddColumns(lastCol, 2)
sheet.Columns(lastCol).Formula = "E1"
sheet.Columns(lastCol + 1).Formula = "D1*E1"
'列ラベルを設定します
Dim colLabels As New List(Of String)()
colLabels.Add("区分")
colLabels.Add("コード")
colLabels.Add("商部")
colLabels.Add("数量")
colLabels.Add("単価")
colLabels.Add("備考")
colLabels.Add("商品名")
colLabels.Add("単位")
colLabels.Add("原価")
colLabels.Add("定価")
colLabels.Add("金額")
For i As Integer = 0 To lastCol + 1
    sheet.Columns(i).Label = colLabels(i)
Next
'テンプレートを作成します
sheet.LayoutMode = SheetView.LayoutModeType.RowTemplateLayoutMode
Dim template As WorksheetTemplate = sheet.WorksheetTemplate
'レイアウトを作成します(列数、列幅)
template.LayoutColumns.Count = 8
template.LayoutColumns(0).Width = 50 '区分           
template.LayoutColumns(1).Width = 200 'コード/商品名
template.LayoutColumns(2).Width = 30 '商部
template.LayoutColumns(3).Width = 90 '定価
template.LayoutColumns(4).Width = 30 '数量/単位
template.LayoutColumns(5).Width = 90 '単価/原価
template.LayoutColumns(6).Width = 90 '金額
template.LayoutColumns(7).Width = 100 '備考
'レイアウトを作成します(行数、行の高さ、セル結合)
template.RowTemplate.RowCount = 2
template.RowTemplate.LayoutRows(0, 1).Height = 20
template.RowTemplate.LayoutCells(0, 0).RowSpan = 2
template.RowTemplate.LayoutCells(0, 2).RowSpan = 2
template.RowTemplate.LayoutCells(0, 7).RowSpan = 2
'テンプレートのセルにデータを割り当てます(1行目)
template.LayoutCells(0, 0).DataIndex = colLabels.IndexOf("区分")
template.LayoutCells(0, 1).DataIndex = colLabels.IndexOf("コード")
template.LayoutCells(0, 2).DataIndex = colLabels.IndexOf("商部")
template.LayoutCells(0, 3).DataIndex = colLabels.IndexOf("定価")
template.LayoutCells(0, 4).DataIndex = colLabels.IndexOf("数量")
template.LayoutCells(0, 5).DataIndex = colLabels.IndexOf("単価")
template.LayoutCells(0, 6).DataIndex = colLabels.IndexOf("金額")
template.LayoutCells(0, 7).DataIndex = colLabels.IndexOf("備考")
'テンプレートのセルにデータを割り当てます(2行目)
template.LayoutCells(1, 1).DataIndex = colLabels.IndexOf("商品名")
template.LayoutCells(1, 4).DataIndex = colLabels.IndexOf("単位")
template.LayoutCells(1, 5).DataIndex = colLabels.IndexOf("原価")
FpSpread1.ClientAutoSize = True

この例では、データソースとして以下のクラスを使用しています。

[Serializable]
public class Order
{
    public string Section { get; set; }
    public string Code { get; set; }
    public string Division { get; set; }
    public decimal? Quantity { get; set; }
    public decimal? UnitPrice { get; set; }
    public string Note { get; set; }
    public string ProductName { get; set; }
    public string UnitTerm { get; set; }
    public decimal? Expense { get; set; }
}
[Serializable]
public class OrderList : List<Order>
{
    public OrderList()
    {
        Add(new Order
        {
            Section = "1.明細",
            Code = "010001",
            ProductName = "長時間録画液晶テレビ 37型 TV-37X1",
            Division = "01",
            Quantity = 1,
            UnitTerm = "台",
            UnitPrice = 65000,
            Expense = 50000,
            Note = "【至急】納品お願いします。"
        });
        Add(new Order
        {
            Section = "1.明細",
            Code = "010002",
            ProductName = "高画質液晶テレビ 47型 TV-47X1",
            Division = "01",
            Quantity = 1,
            UnitTerm = "台",
            UnitPrice = 200000,
            Expense = 155000
        });
        Add(new Order
        {
            Section = "1.明細",
            Code = "010003",
            ProductName = "高画質液晶テレビ 55型 TV-55SX",
            Division = "01",
            Quantity = 1,
            UnitTerm = "台",
            UnitPrice = 800000,
            Expense = 600000
        });
        Add(new Order
        {
            Section = "1.明細",
            Code = "020001",
            ProductName = "DVDレコーダー標準録画 DVD-X2",
            Division = "02",
            Quantity = 1,
            UnitTerm = "台",
            UnitPrice = 50000,
            Expense = 35000
        });
        Add(new Order
        {
            Section = "1.明細",
            Code = "020002",
            ProductName = "DVDレコーダー長時間録画 DVD-X1",
            Division = "02",
            Quantity = 1,
            UnitTerm = "台",
            UnitPrice = 70000,
            Expense = 49000
        });
        Add(new Order
        {
            Section = "1.明細",
            Code = "020003",
            ProductName = "ブルーレイレコーダー長時間録画 BR-X1",
            Division = "02",
            Quantity = 1,
            UnitTerm = "台",
            UnitPrice = 110000,
            Expense = 77000
        });
        Add(new Order
        {
            Section = "1.明細",
            Code = "020004",
            ProductName = "ブルーレイレコーダー同時録画 BR-SX",
            Division = "02",
            Quantity = 1,
            UnitTerm = "台",
            UnitPrice = 200000,
            Expense = 150000
        });
    }   
}
<Serializable>
Public Class Order
    Public Property Section() As String
    Public Property Code() As String
    Public Property Division() As String
    Public Property Quantity() As Nullable(Of Decimal)
    Public Property UnitPrice() As Nullable(Of Decimal)
    Public Property Note() As String
    Public Property ProductName() As String
    Public Property UnitTerm() As String
    Public Property Expense() As Nullable(Of Decimal)
End Class
<Serializable>
Public Class OrderList
    Inherits List(Of Order)
    Public Sub New()
        Add(New Order() With {
            .Section = "1.明細",
            .Code = "010001",
            .ProductName = "長時間録画液晶テレビ 37型 TV-37X1",
            .Division = "01",
            .Quantity = 1,
            .UnitTerm = "台",
            .UnitPrice = 65000,
            .Expense = 50000,
            .Note = "【至急】納品お願いします。"
        })
        Add(New Order() With {
            .Section = "1.明細",
            .Code = "010002",
            .ProductName = "高画質液晶テレビ 47型 TV-47X1",
            .Division = "01",
            .Quantity = 1,
            .UnitTerm = "台",
            .UnitPrice = 200000,
            .Expense = 155000
        })
        Add(New Order() With {
            .Section = "1.明細",
            .Code = "010003",
            .ProductName = "高画質液晶テレビ 55型 TV-55SX",
            .Division = "01",
            .Quantity = 1,
            .UnitTerm = "台",
            .UnitPrice = 800000,
            .Expense = 600000
        })
        Add(New Order() With {
            .Section = "1.明細",
            .Code = "020001",
            .ProductName = "DVDレコーダー標準録画 DVD-X2",
            .Division = "02",
            .Quantity = 1,
            .UnitTerm = "台",
            .UnitPrice = 50000,
            .Expense = 35000
        })
        Add(New Order() With {
            .Section = "1.明細",
            .Code = "020002",
            .ProductName = "DVDレコーダー長時間録画 DVD-X1",
            .Division = "02",
            .Quantity = 1,
            .UnitTerm = "台",
            .UnitPrice = 70000,
            .Expense = 49000
        })
        Add(New Order() With {
            .Section = "1.明細",
            .Code = "020003",
            .ProductName = "ブルーレイレコーダー長時間録画 BR-X1",
            .Division = "02",
            .Quantity = 1,
            .UnitTerm = "台",
            .UnitPrice = 110000,
            .Expense = 77000
        })
        Add(New Order() With {
            .Section = "1.明細",
            .Code = "020004",
            .ProductName = "ブルーレイレコーダー同時録画 BR-SX",
            .Division = "02",
            .Quantity = 1,
            .UnitTerm = "台",
            .UnitPrice = 200000,
            .Expense = 150000
        })
    End Sub
End Class

 

 


© MESCIUS inc. All rights reserved.