[]
↳ TemplateSheet
• new TemplateSheet(name
)
报表模板
代码示例
const spread = new GC.Spread.Sheets.Workbook('spread-host', { sheetCount: 0 });
const reportSheet = spread.addSheetTab(0, 'orders-report', GC.Spread.Sheets.SheetType.reportSheet);
const templateSheet = reportSheet.getTemplate();
templateSheet.setValue(0, 0, 'test');
属性名 | 类型 | 说明 |
---|---|---|
name |
string |
报表模板名称 |
▸ getDataEntrySetting(): DataEntrySetting
获取模板中填报设定
代码示例
// get the data entry setting.
const dataEntrySetting = templateSheet.getDataEntrySetting();
填报设定
▸ getLayoutSetting(): LayoutSetting
获取布局设定
代码示例
// get the layout setting.
const layoutSetting = templateSheet.getLayoutSetting();
布局设定
▸ getPaginationSetting(): IPaginationSetting
获取分页设定
代码示例
// get the pagination setting.
const paginationSetting = templateSheet.getPaginationSetting();
分页设定
▸ getTemplateCell(row
, col
): TemplateCell
获取模板单元格
代码示例
// get the A2 template cell's setting.
const templateCell = templateSheet.getTemplateCell(1, 0);
属性名 | 类型 | 说明 |
---|---|---|
row |
number |
行索引 |
col |
number |
列索引 |
模板单元格
▸ setDataEntrySetting(dataEntrySetting
): void
设置填报设定
代码示例
// add the customers table.
const customersTable = spread.dataManager().addTable('Customers', {
remote: {
read: { url: 'https://demodata.grapecity.com/northwind/api/v1/customers' },
batch: (data) => {
// sync the changes to the server here.
console.log('changes: ', data);
return Promise.resolve(data.map((item) => ({ succeed: true })));
},
},
batch: true,
});
// set binding for the template
const columns = ['customerId', 'companyName', 'contactName', 'contactTitle', 'address', 'region', 'country', 'city', 'postalCode', 'phone', 'fax'];
columns.forEach((columnName, i) => {
templateSheet.setValue(0, i, `${columnName[0].toUpperCase()}${columnName.substring(1)}`);
templateSheet.setTemplateCell(1, i, {
type: 'List',
binding: `Customers[${columnName}]`,
});
});
// config the data entry setting
const customerRule = {
name: 'customers',
tableName: 'Customers',
fields: [
{ formula: 'A2', dbColumnName: 'customerId', isPrimary: true },
{ formula: 'B2', dbColumnName: 'companyName' },
{ formula: 'C2', dbColumnName: 'contactName' },
{ formula: 'D2', dbColumnName: 'contactTitle' },
{ formula: 'E2', dbColumnName: 'address' },
{ formula: 'F2', dbColumnName: 'region' },
{ formula: 'G2', dbColumnName: 'country' },
{ formula: 'H2', dbColumnName: 'city' },
{ formula: 'I2', dbColumnName: 'postalCode' },
{ formula: 'J2', dbColumnName: 'phone' },
{ formula: 'K2', dbColumnName: 'fax' },
],
};
templateSheet.setDataEntrySetting([customerRule]);
属性名 | 类型 | 说明 |
---|---|---|
dataEntrySetting |
DataEntrySetting |
填报设定 |
void
▸ setLayoutSetting(setting
): void
设定布局设定
代码示例
const dataManager = spread.dataManager();
dataManager.addTable("orders",
{
remote: {
read: {
url: "https://demodata.grapecity.com/northwind/api/v1/orders"
}
}
}
);
templateSheet.setTemplateCell(1, 0, { type: 'List', binding: 'orders[orderId]' });
const setting = {
dataRange: "A2",
type: "RowLayout",
rowCount: 10
}
templateSheet.setLayoutSetting(setting);
属性名 | 类型 | 说明 |
---|---|---|
setting |
LayoutSetting |
布局设定 |
void
▸ setPaginationSetting(setting
): void
设定分页设定
代码示例
// set the paper size pagination.
const printInfo = templateSheet.printInfo();
printInfo.paperSize().kind(GC.Spread.Sheets.Print.PaperKind.a4);
templateSheet.setPaginationSetting({
paperSizePagination: true,
titleRow: {
start: 0,
end: 0,
},
titleCol: {
start: 0,
end: 0,
},
paginationOrder: 'OverThenDown',
});
// set row pagination, row pagination only can work for the list template cell.
templateSheet.setTemplateCell(1, 0, { type: 'List', binding: 'orders[orderId]' });
templateSheet.setPaginationSetting({
rowPagination: {
paginationDataCell: 'A2',
rowCountPerPage: 20,
},
titleRow: {
start: 0,
end: 0,
},
});
属性名 | 类型 | 说明 |
---|---|---|
setting |
IPaginationSetting |
分页设定 |
void
▸ setTemplateCell(row
, col
, templateCell
): void
设定模板单元格
代码示例
const dataManager = spread.dataManager();
dataManager.addTable("orders",
{
remote: {
read: {
url: "https://demodata.grapecity.com/northwind/api/v1/orders"
}
}
}
);
// set the template cell setting for the A2 cell.
templateSheet.setTemplateCell(1, 0, { type: 'List', binding: 'orders[shipCity]' });
属性名 | 类型 | 说明 |
---|---|---|
row |
number |
行索引 |
col |
number |
列索引 |
templateCell |
TemplateCell |
模板单元格 |
void