|
|
@@ -136,13 +136,10 @@ namespace UAS_MES_NEW.Query
|
|
|
int rowSliceSize = int.Parse(RowCount.Value.ToString());
|
|
|
int imageIndex = 1;
|
|
|
|
|
|
- // ========== 计算总页数 ==========
|
|
|
+ // ========== 核心修改:手动计算总页数 ==========
|
|
|
+ // 总页数 = 总行数 除以 每页行数,向上取整
|
|
|
int totalPages = (int)Math.Ceiling((double)totalRows / rowSliceSize);
|
|
|
- // 清除原有页脚,防止干扰
|
|
|
- she.PageSetup.SetFooter(0, ""); // 左
|
|
|
- she.PageSetup.SetFooter(1, ""); // 中
|
|
|
- she.PageSetup.SetFooter(2, ""); // 右
|
|
|
- // =================================
|
|
|
+ // ============================================
|
|
|
|
|
|
// 记录原表设置,循环结束后恢复,避免污染原文件
|
|
|
string originalPrintArea = she.PageSetup.PrintArea;
|
|
|
@@ -159,6 +156,11 @@ namespace UAS_MES_NEW.Query
|
|
|
she.PageSetup.TopMargin = 0;
|
|
|
she.PageSetup.BottomMargin = 0;
|
|
|
|
|
|
+ // 循环开始前先彻底清空原有页脚,防止残留格式干扰
|
|
|
+ she.PageSetup.SetFooter(0, "");
|
|
|
+ she.PageSetup.SetFooter(1, "");
|
|
|
+ she.PageSetup.SetFooter(2, "");
|
|
|
+
|
|
|
for (int startRow = 0; startRow < totalRows; startRow += rowSliceSize)
|
|
|
{
|
|
|
int endRow = Math.Min(startRow + rowSliceSize - 1, totalRows - 1);
|
|
|
@@ -185,12 +187,12 @@ namespace UAS_MES_NEW.Query
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // ========== 设置当前页的全局页码 ==========
|
|
|
- // 使用脚本命令拼接:当前页 &P ,总页数 &N
|
|
|
- string pageFooter = $"&P / &N";
|
|
|
- // 放置在页脚中间 (Section 1)
|
|
|
+ // ========== 核心修改:手动写入硬编码页脚 ==========
|
|
|
+ // 当前 page 是 imageIndex,总页数是我们刚才算的 totalPages
|
|
|
+ string pageFooter = $"第 {imageIndex} 页 / 共 {totalPages} 页";
|
|
|
+ // 直接写入页脚中间位置
|
|
|
she.PageSetup.SetFooter(1, pageFooter);
|
|
|
- // =========================================
|
|
|
+ // ================================================
|
|
|
|
|
|
// 2. 创建渲染选项
|
|
|
ImageOrPrintOptions options = new ImageOrPrintOptions();
|
|
|
@@ -210,7 +212,7 @@ namespace UAS_MES_NEW.Query
|
|
|
bitmap.Dispose();
|
|
|
//sr.Dispose(); // 如果旧版本这里报错,可以保留注释
|
|
|
|
|
|
- imageIndex++;
|
|
|
+ imageIndex++; // 这一行对应下一张图片的页码,放在这里即可
|
|
|
OperatResult.AppendText("解析图片【" + imagePath + "】" + "\n");
|
|
|
|
|
|
// 5. 上传与入库
|
|
|
@@ -232,11 +234,10 @@ namespace UAS_MES_NEW.Query
|
|
|
she.PageSetup.TopMargin = originalTopMargin;
|
|
|
she.PageSetup.BottomMargin = originalBottomMargin;
|
|
|
|
|
|
- // ========== 恢复原表页脚 ==========
|
|
|
+ // 循环结束后彻底清空页脚,防止影响下次使用
|
|
|
she.PageSetup.SetFooter(0, "");
|
|
|
she.PageSetup.SetFooter(1, "");
|
|
|
she.PageSetup.SetFooter(2, "");
|
|
|
- // ================================
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|