处理表格

This commit is contained in:
2025-03-14 17:16:46 +08:00
parent d326afc26c
commit 43279b6a99
2 changed files with 13 additions and 25 deletions

View File

@@ -231,14 +231,6 @@ export default {
var colspan = gridSpan ? parseInt(gridSpan.getAttribute("w:val"), 10) : 1; var colspan = gridSpan ? parseInt(gridSpan.getAttribute("w:val"), 10) : 1;
var rowspan = 1; var rowspan = 1;
// if (vMerge) {
// if (vMerge.getAttribute("w:val") === "restart") {
// rowspan = 4;
// } else {
// continue;
// }
// }
if (vMerge) { if (vMerge) {
if (vMerge.getAttribute("w:val") === "restart") { if (vMerge.getAttribute("w:val") === "restart") {
rowspan = 1; // 初始化 rowspan rowspan = 1; // 初始化 rowspan
@@ -247,22 +239,22 @@ export default {
while (nextRowIdx < rows.length) { while (nextRowIdx < rows.length) {
const nextRowCells = rows[nextRowIdx].getElementsByTagNameNS(namespace, "tc"); const nextRowCells = rows[nextRowIdx].getElementsByTagNameNS(namespace, "tc");
console.log(`🔍 检查下一行单元格 at row ${nextRowIdx}, col ${cellIndex}:`, nextRowCells); // console.log(`🔍 检查下一行单元格 at row ${nextRowIdx}, col ${cellIndex}:`, nextRowCells);
if (nextRowCells.length > cellIndex) { if (nextRowCells.length > cellIndex) {
const nextCell = nextRowCells[cellIndex]; const nextCell = nextRowCells[cellIndex];
if (!nextCell) { if (!nextCell) {
console.warn(`⚠️ nextCell 未定义 at row ${nextRowIdx}, col ${cellIndex}`); // console.warn(`⚠️ nextCell 未定义 at row ${nextRowIdx}, col ${cellIndex}`);
break; break;
} }
const nextVMerge = nextCell.getElementsByTagNameNS(namespace, "vMerge")[0]; const nextVMerge = nextCell.getElementsByTagNameNS(namespace, "vMerge")[0];
console.log(`🔍 检查 nextVMerge at row ${nextRowIdx}, col ${cellIndex}:`, nextVMerge); // console.log(`🔍 检查 nextVMerge at row ${nextRowIdx}, col ${cellIndex}:`, nextVMerge);
// **如果 nextVMerge 为空,则不应继续增长 rowspan** // **如果 nextVMerge 为空,则不应继续增长 rowspan**
if (!nextVMerge) { if (!nextVMerge) {
console.log(`⚠️ nextVMerge 为空 at row ${nextRowIdx}, col ${cellIndex} - 停止扩展`); // console.log(`⚠️ nextVMerge 为空 at row ${nextRowIdx}, col ${cellIndex} - 停止扩展`);
break; break;
} }
@@ -272,21 +264,21 @@ export default {
if (!vMergeVal || vMergeVal === "continue") { if (!vMergeVal || vMergeVal === "continue") {
if (rowspan < maxRowspan) { // 限制 rowspan 最大值 if (rowspan < maxRowspan) { // 限制 rowspan 最大值
rowspan++; rowspan++;
console.log(`✅ rowspan 扩展到: ${rowspan} (row: ${nextRowIdx}, col: ${cellIndex})`); // console.log(`✅ rowspan 扩展到: ${rowspan} (row: ${nextRowIdx}, col: ${cellIndex})`);
nextRowIdx++; nextRowIdx++;
} else { } else {
console.log(`⛔ 最大 rowspan 限制 ${rowspan},在 row ${nextRowIdx} 停止`); // console.log(`⛔ 最大 rowspan 限制 ${rowspan},在 row ${nextRowIdx} 停止`);
break; break;
} }
} else if (vMergeVal === "restart") { } else if (vMergeVal === "restart") {
console.log(`⛔ 停止 rowspan 扩展 at row ${nextRowIdx}, 因为 w:val="restart"`); // console.log(`⛔ 停止 rowspan 扩展 at row ${nextRowIdx}, 因为 w:val="restart"`);
break; break;
} else { } else {
console.log(`⚠️ 未知 w:val="${vMergeVal}" at row ${nextRowIdx},停止合并`); // console.log(`⚠️ 未知 w:val="${vMergeVal}" at row ${nextRowIdx},停止合并`);
break; break;
} }
} else { } else {
console.warn(`⚠️ Row ${nextRowIdx} 没有足够的列 cellIndex ${cellIndex}`); // console.warn(`⚠️ Row ${nextRowIdx} 没有足够的列 cellIndex ${cellIndex}`);
break; break;
} }
} }
@@ -295,10 +287,6 @@ export default {
} }
} }
console.log('rowspan at line 265:', rowspan) console.log('rowspan at line 265:', rowspan)
const currentLevelNumbers = {}; const currentLevelNumbers = {};
for (const paragraph of paragraphs) { for (const paragraph of paragraphs) {

View File

@@ -2,12 +2,12 @@
//记得切换 //记得切换
//正式 //正式
// const mediaUrl = '/public/'; const mediaUrl = '/public/';
// const baseUrl = '/'; const baseUrl = '/';
const mediaUrl = 'https://submission.tmrjournals.com/public/'; // const mediaUrl = 'https://submission.tmrjournals.com/public/';
const baseUrl = '/api'; // const baseUrl = '/api';