SmartMarkersのフォーマット設定
スタイル属性のコピー
スマートマーカーtagsを持つセルのスタイルをコピーする場合には、そのためにスマートマーカーtagsのCopyStyle属性を使用することができます。
スマートマーカーを含むセルからスタイルをコピーするための簡単な例です。この例では、A2およびB2のセルに2つのマーカーが使用されています。セルB2に貼り付けられたマーカーはCopyStyle属性を使用していますが、セルA2のマーカーは使用していません。簡単な書式設定(たとえばフォントの色を赤に設定し、セルの塗りつぶし色をイエローに設定します)。
この例では、A2およびB2のセルに2つのマーカーを持つシンプルなテンプレートMicrosoft Excelファイルが使用されています。セルB2に貼り付けられたマーカーはCopyStyle属性を使用し、一方、セルA2のマーカーは使用していません。簡単なフォーマット(例:フォントの色を赤に設定し、セルの背景色を黄に設定)を適用します。
コードを実行すると、Aspose.Cells は列Bのすべてのレコードに書式をコピーしますが、列Aの書式は保持しません。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create Students DataTable | |
DataTable dtStudent = new DataTable("Student"); | |
// Define a field in it | |
DataColumn dcName = new DataColumn("Name", typeof(string)); | |
dtStudent.Columns.Add(dcName); | |
// Add three rows to it | |
DataRow drName1 = dtStudent.NewRow(); | |
DataRow drName2 = dtStudent.NewRow(); | |
DataRow drName3 = dtStudent.NewRow(); | |
drName1["Name"] = "John"; | |
drName2["Name"] = "Jack"; | |
drName3["Name"] = "James"; | |
dtStudent.Rows.Add(drName1); | |
dtStudent.Rows.Add(drName2); | |
dtStudent.Rows.Add(drName3); | |
string filePath = dataDir + "TestSmartMarkers.xlsx"; | |
// Create a workbook from Smart Markers template file | |
Workbook workbook = new Workbook(filePath); | |
// Instantiate a new WorkbookDesigner | |
WorkbookDesigner designer = new WorkbookDesigner(); | |
// Specify the Workbook | |
designer.Workbook = workbook; | |
// Set the Data Source | |
designer.SetDataSource(dtStudent); | |
// Process the smart markers | |
designer.Process(); | |
// Save the Excel file | |
workbook.Save(dataDir+ "output.xlsx", SaveFormat.Xlsx); |
カスタムラベルの追加
紹介
Smart Markersのグループ化データ機能を使用する場合、時々サマリー行に独自のカスタムラベルを追加する必要があります。また、列の名前をそのラベルと連結したい場合があります。例えば、“注文の小計” のように. Aspose.Cells はラベルと LabelPosition 属性を提供しているため、グループ化データの Smart Markers にカスタムラベルを配置し、サマリー行と連結することができます。
Smart Markers内の小計行にカスタムラベルを追加
この例では、データファイル と テンプレートファイル にいくつかのマーカーを含むセルが使用されます。コードを実行すると、Aspose.Cells はグループ化されたデータのサマリー行にいくつかのカスタムラベルを追加します。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate the workbook from a template file that contains Smart Markers | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
Workbook designer = new Workbook(dataDir + "SmartMarker_Designer.xlsx"); | |
// Export data from the first worksheet to fill a data table | |
DataTable dt = workbook.Worksheets[0].Cells.ExportDataTable(0, 0, 11, 5, true); | |
// Set the table name | |
dt.TableName = "Report"; | |
// Instantiate a new WorkbookDesigner | |
WorkbookDesigner d = new WorkbookDesigner(); | |
// Specify the workbook to the designer book | |
d.Workbook = designer; | |
// Set the data source | |
d.SetDataSource(dt); | |
// Process the smart markers | |
d.Process(); | |
// Save the Excel file | |
designer.Save(dataDir + "output.xlsx", SaveFormat.Xlsx); |