171a4b2f by lxs

入表功调整

1 parent f2779784
......@@ -440,8 +440,8 @@ const addSameData = (rIndex, name, level, tData) => {
const lastCode = rowData[`code${level - 1}`];
const tCode = tData[`code${level}`].split(lastCode)[1];
const codeVal = parseInt(tCode, 10) < 10 ? `0${parseInt(tCode, 10) + 1}` : parseInt(tCode, 10) + 1;
for(var r in rowData){
if(r.indexOf('name') == -1 && r.indexOf('code') == -1) rowData[r] = '';
for (var r in rowData) {
if (r.indexOf('name') == -1 && r.indexOf('code') == -1) rowData[r] = '';
}
rowData[`name${level}`] = name;
rowData[`code${level}`] = `${lastCode}${codeVal}`;
......@@ -458,8 +458,8 @@ const addLowerData = (rIndex, name, level, len) => {
const hasLowerItem = rowData[`code${level + 1}`] ? true : false;
const lastCode = rowData[`code${level}`];
const codeVal = (len + 1) < 10 ? '0' + (len + 1) : len + 1;
for(var r in rowData){
if(r.indexOf('name') == -1 && r.indexOf('code') == -1) rowData[r] = '';
for (var r in rowData) {
if (r.indexOf('name') == -1 && r.indexOf('code') == -1) rowData[r] = '';
}
rowData[`name${level + 1}`] = name;
rowData[`code${level + 1}`] = `${lastCode}${codeVal}`;
......@@ -928,6 +928,25 @@ const s2ab = (s) => {
return buf;
}
// 定义边框样式 - 实线边框
const borderStyle = {
top: { style: 'thin', color: { rgb: 'D9D9D9' } },
bottom: { style: 'thin', color: { rgb: 'D9D9D9' } },
left: { style: 'thin', color: { rgb: 'D9D9D9' } },
right: { style: 'thin', color: { rgb: 'D9D9D9' } }
};
// 字体配置
const defaultFont = {
name: '宋体', // 字体名称
sz: 14 * 0.75, // 字体大小(磅)
color: { rgb: '212121' } // 黑色
};
// 设置行高(单位:磅,1px≈0.75磅)
const defaultRowHeightInPx = 36; // 默认行高36px
const headerRowHeightInPx = 32; // 表头行高32px
// 生成成本设置表
const exportDetailsToExcel = async () => {
// 准备工作表数据
......@@ -1002,14 +1021,29 @@ const exportDetailsToExcel = async () => {
// 自动调整列宽
const colWidths = fields.map((field, index) => {
const defaultWidth = field.width || 100 // 默认宽度100
const colWidth = defaultWidth / 14 + 2; // 留一些余地
const colWidth = defaultWidth * 0.75; // 留一些余地
// 取表头宽度和内容宽度的较大值
return { wpx: colWidth * 12 } // 使用像素宽度
return { wpx: colWidth } // 使用像素宽度
})
ws['!cols'] = colWidths
// 转换为磅(Excel使用磅作为单位)
const defaultRowHeight = defaultRowHeightInPx * 0.75;
const headerRowHeight = headerRowHeightInPx * 0.75;
// 初始化行高设置
ws['!rows'] = [];
// 设置表头行高
ws['!rows'][0] = { hpt: headerRowHeight, customHeight: true };
// 设置数据行高
for (let i = 1; i < wsData.length; i++) {
ws['!rows'][i] = { hpt: defaultRowHeight, customHeight: true };
}
// 设置合并单元格
const merges = []
......@@ -1051,13 +1085,16 @@ const exportDetailsToExcel = async () => {
alignment: {
vertical: 'center',
horizontal: 'left'
}
},
font: defaultFont,
border: borderStyle // 添加边框样式
}
// 表头样式
if (R === 0) {
ws[cellAddress].s = {
...defaultStyle,
fill: { fgColor: { rgb: 'F2F2F2' } } // 表头背景色(可选)
}
continue
}
......@@ -1138,14 +1175,29 @@ const exportBookToExcel = async () => {
// 自动调整列宽
const colWidths = bookHeaders.value.map((field, index) => {
const defaultWidth = field.width || 100 // 默认宽度100
const colWidth = defaultWidth / 14 + 2; // 留一些余地
const colWidth = defaultWidth * 0.75; // 留一些余地
// 取表头宽度和内容宽度的较大值
return { wpx: colWidth * 12 } // 使用像素宽度
return { wpx: colWidth } // 使用像素宽度
})
ws['!cols'] = colWidths
// 转换为磅(Excel使用磅作为单位)
const defaultRowHeight = defaultRowHeightInPx * 0.75;
const headerRowHeight = headerRowHeightInPx * 0.75;
// 初始化行高设置
ws['!rows'] = [];
// 设置表头行高
ws['!rows'][0] = { hpt: headerRowHeight, customHeight: true };
// 设置数据行高
for (let i = 1; i < wsData.length; i++) {
ws['!rows'][i] = { hpt: defaultRowHeight, customHeight: true };
}
// 设置单元格样式
const range = XLSXS.utils.decode_range(ws['!ref'])
// 数值字段(除title外的所有字段)
......@@ -1165,14 +1217,16 @@ const exportBookToExcel = async () => {
alignment: {
vertical: 'center',
horizontal: 'left'
}
},
font: defaultFont,
border: borderStyle // 添加边框样式
}
// 表头样式(第1行)
if (R === 0) {
ws[cellAddress].s = {
...defaultStyle,
// font: { bold: true } // 表头加粗
fill: { fgColor: { rgb: 'F2F2F2' } } // 表头背景色(可选)
}
continue
}
......@@ -1187,10 +1241,11 @@ const exportBookToExcel = async () => {
// 数值列特殊处理(无论是否最后一行)
if (isNumeric) {
ws[cellAddress].s = {
...defaultStyle,
alignment: {
vertical: 'center',
horizontal: 'right'
}
},
};
// 确保数值被正确识别为数字类型
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!