作成日: 2022/03/11 最終更新日: 2022/03/30
文書種別
使用方法
詳細
MultiRowにはExcelのXLSXファイルを直接取り扱う機能は提供されていません。ここでは、アドバンスソフトウェア株式会社の「ExcelCreator 8.0 for .NET」を使用してMultiRowのデータをXLSXファイルとして入出力する例を紹介します。
※MultiRowにはExcelCreator 8.0 for .NETのライセンスは含まれません。別途アドバンスソフトウェア株式会社よりご購入ください。
XLSファイルの作成
次のコードは、サンプルとして使用するXLSXファイルを出力します。
[Visual Basic]
[C#]
XLS ファイルの読み込み
次のコードは、上記のサンプルで作成した XLSX ファイルの内容を GcMultiRow コントロールに表示します。
[Visual Basic]
[C#]
※MultiRowにはExcelCreator 8.0 for .NETのライセンスは含まれません。別途アドバンスソフトウェア株式会社よりご購入ください。
XLSファイルの作成
次のコードは、サンプルとして使用するXLSXファイルを出力します。
[Visual Basic]
Imports GrapeCity.Win.MultiRow
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' サンプルのグリッドを作成します
Dim textBoxCell1 As New TextBoxCell
textBoxCell1.Name = "textBoxCell1"
Dim textBoxCell2 As New TextBoxCell
textBoxCell2.Name = "textBoxCell2"
GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {textBoxCell1, textBoxCell2})
GcMultiRow1.RowCount = 5
GcMultiRow1.SuspendLayout()
For i As Integer = 0 To GcMultiRow1.RowCount - 1
GcMultiRow1.SetValue(i, "textBoxCell1", "ABC")
GcMultiRow1.SetValue(i, "textBoxCell2", "日本語")
Next
GcMultiRow1.ResumeLayout()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim XlsxCreator1 As New AdvanceSoftware.ExcelCreator.Xlsx.XlsxCreator()
XlsxCreator1.CreateBook("C:¥test.xlsx", 1, AdvanceSoftware.ExcelCreator.xlsxVersion.ver2007)
For rowIndex As Integer = 0 To GcMultiRow1.RowCount - 1
For cellIndex As Integer = 0 To GcMultiRow1.Template.Row.Cells.Count - 1
XlsxCreator1.Pos(cellIndex, rowIndex).Str = GcMultiRow1.Rows(rowIndex).Cells(cellIndex).DisplayText
Next
Next
XlsxCreator1.CloseBook(True)
XlsxCreator1.Dispose()
End Sub
[C#]
using GrapeCity.Win.MultiRow;
private void Form1_Load(object sender, EventArgs e)
{
TextBoxCell textBoxCell1 = new TextBoxCell();
textBoxCell1.Name = "textBoxCell1";
TextBoxCell textBoxCell2 = new TextBoxCell();
textBoxCell2.Name = "textBoxCell2";
gcMultiRow1.Template = Template.CreateGridTemplate(new Cell[] { textBoxCell1, textBoxCell2 });
gcMultiRow1.RowCount = 5;
gcMultiRow1.SuspendLayout();
for (int i = 0; i < gcMultiRow1.RowCount; i++)
{
gcMultiRow1.SetValue(i, "textBoxCell1", "ABC");
gcMultiRow1.SetValue(i, "textBoxCell2", "日本語");
}
gcMultiRow1.ResumeLayout();
}
private void button1_Click(object sender, EventArgs e)
{
AdvanceSoftware.ExcelCreator.Xlsx.XlsxCreator xlsxCreator1 = new AdvanceSoftware.ExcelCreator.Xlsx.XlsxCreator();
xlsxCreator1.CreateBook(@"C:¥test.xlsx", 1, AdvanceSoftware.ExcelCreator.xlsxVersion.ver2007);
for (int rowIndex = 0; rowIndex < gcMultiRow1.RowCount; rowIndex++)
{
for (int cellIndex = 0; cellIndex < gcMultiRow1.Template.Row.Cells.Count; cellIndex++)
{
xlsxCreator1.Pos(cellIndex, rowIndex).Str = gcMultiRow1.Rows[rowIndex].Cells[cellIndex].DisplayText;
}
}
xlsxCreator1.CloseBook(true);
xlsxCreator1.Dispose();
}
XLS ファイルの読み込み
次のコードは、上記のサンプルで作成した XLSX ファイルの内容を GcMultiRow コントロールに表示します。
[Visual Basic]
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim XlsxCreator1 As New AdvanceSoftware.ExcelCreator.Xlsx.XlsxCreator()
GcMultiRow1.RowCount = 1
GcMultiRow1.RowCount = 5
XlsxCreator1.ReadBook("C:¥test.xlsx")
For rowIndex As Integer = 0 To XlsxCreator1.GetMaxData(AdvanceSoftware.ExcelCreator.MaxEndPoint.MaxPoint).Y
For cellIndex As Integer = 0 To XlsxCreator1.GetMaxData(AdvanceSoftware.ExcelCreator.MaxEndPoint.MaxPoint).X
GcMultiRow1.SetValue(rowIndex, cellIndex, XlsxCreator1.Pos(cellIndex, rowIndex).Str)
Next
Next
XlsxCreator1.CloseBook(True)
XlsxCreator1.Dispose()
End Sub
[C#]
private void button2_Click(object sender, EventArgs e)
{
AdvanceSoftware.ExcelCreator.Xlsx.XlsxCreator xlsxCreator1 = new AdvanceSoftware.ExcelCreator.Xlsx.XlsxCreator();
gcMultiRow1.RowCount = 1;
gcMultiRow1.RowCount = 5;
xlsxCreator1.ReadBook(@"C:¥test.xlsx");
for (int rowIndex = 0; rowIndex < xlsxCreator1.GetMaxData(AdvanceSoftware.ExcelCreator.MaxEndPoint.MaxPoint).Y + 1; rowIndex++)
{
for (int cellIndex = 0; cellIndex < xlsxCreator1.GetMaxData(AdvanceSoftware.ExcelCreator.MaxEndPoint.MaxPoint).X + 1; cellIndex++)
{
gcMultiRow1.SetValue(rowIndex, cellIndex, xlsxCreator1.Pos(cellIndex, rowIndex).Str);
}
}
xlsxCreator1.CloseBook(true);
xlsxCreator1.Dispose();
}