如何使用reactjs设置excel工作表的列宽


import Workbook from 'react-xlsx-workbook';
var obj={};
obj['id'] = users._id
obj['sessionCreatedDate'] = users.sessionCreatedDate;
obj['sessionUpdatedDate'] = users.sessionUpdatedDate;
data1.push(JSON.parse(JSON.stringify(obj)));
<Workbook>
<Workbook.Sheet data={() =>data1}  name="Sheet A">
<Workbook.Column label="Session Start Date" value="sessionStartDate"/> 
<Workbook.Column label="Session Start Time" value="sessionStartTime"/> 
<Workbook.Column label="Session Created Date" value="sessionCreatedDate"/>
</Workbook.Sheet>
</Workbook>

我认为您可能需要为正在创建的表设置一些配置,从下面的代码段中获取参考,或者访问https://www.grapecity.com/blogs/add-excel-import-and-export-to-a-react-app:

const config = {
sheetName: 'Sales Data',
hostClass: ' spreadsheet',
autoGenerateColumns: false,
width: 200,
visible: true,
resizable: true,
priceFormatter: '$ #.00',
chartKey: 1
}
<TablePanel key={config.chartKey} title="Recent Sales">
<SpreadSheets hostClass={config.hostClass}>
<Worksheet name={config.sheetName} dataSource={tableData} autoGenerateColumns= 
{config.autoGenerateColumns}>
<Column width={50} dataField='id' headerText="ID"></Column>
<Column width={200} dataField='client' headerText="Client"></Column>
<Column width={320} dataField='description' headerText="Description"> 
</Column>
<Column width={100} dataField='value' headerText="Value" formatter= 
{config.priceFormatter} resizable="resizable"></Column>
<Column width={100} dataField='itemCount' headerText="Quantity"></Column>
<Column width={100} dataField='soldBy' headerText="Sold By"></Column>
<Column width={100} dataField='country' headerText="Country"></Column>                   
</Worksheet>
</SpreadSheets>
</TablePanel>

最新更新