[]
↳ TemplateSheet
• new TemplateSheet(name)
表示一个 TemplateSheet。
example
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 | Type | Description |
|---|---|---|
name |
string |
模板表的名称。 |
▸ getDataEntrySetting(): DataEntrySetting
获取数据输入设置。
example
// 获取数据输入设置。
const dataEntrySetting = templateSheet.getDataEntrySetting();
返回数据输入设置。
▸ getLayoutSetting(): LayoutSetting
获取布局设置。
example
// 获取布局设置。
const layoutSetting = templateSheet.getLayoutSetting();
返回布局设置。
▸ getPaginationSetting(): IPaginationSetting
获取分页设置。
example
// 获取分页设置。
const paginationSetting = templateSheet.getPaginationSetting();
返回分页设置。
▸ getTemplateCell(row, col): TemplateCell
获取模板单元格。
example
// 获取 A2 模板单元格的设置。
const templateCell = templateSheet.getTemplateCell(1, 0);
| Name | Type | Description |
|---|---|---|
row |
number |
行索引。 |
col |
number |
列索引。 |
返回模板单元格。
▸ setDataEntrySetting(dataEntrySetting): void
设置数据输入设置。
example
// 添加 customers 表。
const customersTable = spread.dataManager().addTable('Customers', {
remote: {
read: { url: 'https://demodata.grapecity.com//northwind/api/v1/customers' },
batch: (data) => {
// 同步变更到服务端
console.log('changes: ', data);
return Promise.resolve(data.map((item) => ({ succeed: true })));
},
},
batch: true,
});
// 为模板设置绑定
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}]`,
});
});
// 配置数据输入设置
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]);
| Name | Type | Description |
|---|---|---|
dataEntrySetting |
DataEntrySetting |
数据输入设置。 |
void
▸ setLayoutSetting(setting): void
设置布局设置。
example
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);
| Name | Type | Description |
|---|---|---|
setting |
LayoutSetting |
布局设置。 |
void
▸ setPaginationSetting(setting): void
设置分页设置。
example
// 设置纸张大小分页。
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',
});
// 设置行分页,行分页仅适用于列表模板单元格。
templateSheet.setTemplateCell(1, 0, { type: 'List', binding: 'orders[orderId]' });
templateSheet.setPaginationSetting({
rowPagination: {
paginationDataCell: 'A2',
rowCountPerPage: 20,
},
titleRow: {
start: 0,
end: 0,
},
});
| Name | Type | Description |
|---|---|---|
setting |
IPaginationSetting |
分页设置。 |
void
▸ setTemplateCell(row, col, templateCell): void
设置模板单元格。
example
const dataManager = spread.dataManager();
dataManager.addTable("orders",
{
remote: {
read: {
url: "https://demodata.grapecity.com/northwind/api/v1/Orders"
}
}
}
);
// 设置 A2 单元格的模板单元格设置。
templateSheet.setTemplateCell(1, 0, { type: 'List', binding: 'orders[shipCity]' });
| Name | Type | Description |
|---|---|---|
row |
number |
行索引。 |
col |
number |
列索引。 |
templateCell |
TemplateCell |
模板单元格。 |
void