|
|
@@ -133,9 +133,8 @@ namespace UAS_MES_NEW.Query
|
|
|
// ---------- 基础参数 ----------
|
|
|
int lastColIndex = she.Cells.MaxDataColumn + 3;
|
|
|
string lastColLetter = CellsHelper.ColumnIndexToName(lastColIndex);
|
|
|
- const int headerRows = 3; // 表头行数(每页都保留)
|
|
|
+ const int headerRows = 3;
|
|
|
int dataRowsPerPage = int.Parse(RowCount.Value.ToString());
|
|
|
- // 计算"内容最大行"时包含图片和形状的底部锚点行
|
|
|
int contentMaxRow = she.Cells.MaxDataRow;
|
|
|
for (int p = 0; p < she.Pictures.Count; p++)
|
|
|
{
|
|
|
@@ -147,22 +146,15 @@ namespace UAS_MES_NEW.Query
|
|
|
if (she.Shapes[s].LowerRightRow > contentMaxRow)
|
|
|
contentMaxRow = she.Shapes[s].LowerRightRow;
|
|
|
}
|
|
|
-
|
|
|
- // ========== ★ 修改点1:totalRows 向上取整到完整页数 ==========
|
|
|
- // 原来:int totalRows = contentMaxRow + 1; → 最后一页只到实际数据行,空白被截掉
|
|
|
- // 现在:先算实际数据行数和页数,再把 totalRows 补足为 headerRows + 总页数 × 每页行数
|
|
|
- // 这样最后一页即使数据不足,也会保留完整的 dataRowsPerPage 行空白
|
|
|
int actualDataRows = Math.Max(contentMaxRow + 1 - headerRows, 0);
|
|
|
int totalPages = (int)Math.Ceiling(actualDataRows / (double)dataRowsPerPage);
|
|
|
if (totalPages == 0) totalPages = 1;
|
|
|
int totalRows = headerRows + totalPages * dataRowsPerPage;
|
|
|
- // ========== ★ 修改点1结束 ==========
|
|
|
-
|
|
|
int totalDataRows = Math.Max(totalRows - headerRows, 0);
|
|
|
- // 水印在原表中的目标行/列
|
|
|
int wmRowGlobal = int.Parse(Y.Value.ToString());
|
|
|
int wmCol = int.Parse(X.Value.ToString());
|
|
|
int imageIndex = 1;
|
|
|
+
|
|
|
for (int page = 0; page < totalPages; page++)
|
|
|
{
|
|
|
// ---------- 1. 复制原表到临时工作表 ----------
|
|
|
@@ -170,9 +162,9 @@ namespace UAS_MES_NEW.Query
|
|
|
Worksheet newshe = workbook.Worksheets[newSheetIndex];
|
|
|
newshe.Copy(she);
|
|
|
newshe.Name = $"Temp_{page}";
|
|
|
- // 本页在原表中的数据行区间(原表坐标,0-based)
|
|
|
int dataStartRow = headerRows + page * dataRowsPerPage;
|
|
|
int dataEndRow = Math.Min(headerRows + (page + 1) * dataRowsPerPage - 1, totalRows - 1);
|
|
|
+
|
|
|
// ---------- 2. 按页过滤原表图片(Pictures) ----------
|
|
|
for (int p = newshe.Pictures.Count - 1; p >= 0; p--)
|
|
|
{
|
|
|
@@ -185,33 +177,19 @@ namespace UAS_MES_NEW.Query
|
|
|
newshe.Pictures.RemoveAt(p);
|
|
|
}
|
|
|
}
|
|
|
- // ---------- 3. 按页过滤原表形状(Shapes:文本框/箭头/连接线等) ----------
|
|
|
+ // ---------- 3. 按页过滤原表形状(Shapes) ----------
|
|
|
for (int s = newshe.Shapes.Count - 1; s >= 0; s--)
|
|
|
{
|
|
|
Aspose.Cells.Drawing.Shape shape;
|
|
|
- try
|
|
|
- {
|
|
|
- shape = newshe.Shapes[s];
|
|
|
- }
|
|
|
- catch
|
|
|
- {
|
|
|
- // 下标已经失效,直接跳过
|
|
|
- continue;
|
|
|
- }
|
|
|
+ try { shape = newshe.Shapes[s]; }
|
|
|
+ catch { continue; }
|
|
|
int topRow = shape.UpperLeftRow;
|
|
|
bool isHeaderShape = topRow < headerRows;
|
|
|
bool belongsToPage = topRow >= dataStartRow && topRow <= dataEndRow;
|
|
|
if (!isHeaderShape && !belongsToPage)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- newshe.Shapes.RemoveAt(s);
|
|
|
- }
|
|
|
- catch
|
|
|
- {
|
|
|
- // GroupShape组合形状无法直接RemoveAt,就隐藏
|
|
|
- shape.IsHidden = true;
|
|
|
- }
|
|
|
+ try { newshe.Shapes.RemoveAt(s); }
|
|
|
+ catch { shape.IsHidden = true; }
|
|
|
}
|
|
|
}
|
|
|
// ---------- 4. 清空非本页单元格内容 ----------
|
|
|
@@ -231,32 +209,16 @@ namespace UAS_MES_NEW.Query
|
|
|
// ---------- 6. 页面设置 ----------
|
|
|
int printMaxRow = newshe.Cells.MaxDataRow;
|
|
|
for (int p = 0; p < newshe.Pictures.Count; p++)
|
|
|
- {
|
|
|
- if (newshe.Pictures[p].LowerRightRow > printMaxRow)
|
|
|
- printMaxRow = newshe.Pictures[p].LowerRightRow;
|
|
|
- }
|
|
|
+ if (newshe.Pictures[p].LowerRightRow > printMaxRow) printMaxRow = newshe.Pictures[p].LowerRightRow;
|
|
|
for (int s = 0; s < newshe.Shapes.Count; s++)
|
|
|
- {
|
|
|
- if (newshe.Shapes[s].LowerRightRow > printMaxRow)
|
|
|
- printMaxRow = newshe.Shapes[s].LowerRightRow;
|
|
|
- }
|
|
|
+ if (newshe.Shapes[s].LowerRightRow > printMaxRow) printMaxRow = newshe.Shapes[s].LowerRightRow;
|
|
|
int newTotalRows = printMaxRow + 1;
|
|
|
-
|
|
|
- // ========== ★ 修改点2:PrintArea 固定页高,最后一页空白行也显示 ==========
|
|
|
- // 原来:最后一页 PrintArea 只到 newTotalRows(实际内容行),空白被截掉
|
|
|
- // 现在:打印区高度取 max(实际内容行, 表头+每页行数),保证每页等高
|
|
|
int pageHeight = headerRows + dataRowsPerPage;
|
|
|
int printEndRow = Math.Max(newTotalRows, pageHeight);
|
|
|
-
|
|
|
if (i == 0)
|
|
|
- {
|
|
|
newshe.PageSetup.PrintArea = $"A1:{lastColLetter}{25}";
|
|
|
- }
|
|
|
else
|
|
|
- {
|
|
|
newshe.PageSetup.PrintArea = $"A1:{lastColLetter}{printEndRow}";
|
|
|
- }
|
|
|
- // ========== ★ 修改点2结束 ==========
|
|
|
|
|
|
newshe.PageSetup.CenterHorizontally = true;
|
|
|
newshe.PageSetup.CenterVertically = true;
|
|
|
@@ -267,7 +229,7 @@ namespace UAS_MES_NEW.Query
|
|
|
newshe.PageSetup.SetFooter(0, "");
|
|
|
newshe.PageSetup.SetFooter(1, "");
|
|
|
newshe.PageSetup.SetFooter(2, "");
|
|
|
- // ---------- 7. 插入水印(额外图片,坐标映射到压缩后本页) ----------
|
|
|
+ // ---------- 7. 插入水印 ----------
|
|
|
if (File.Exists(PrintPath.Text))
|
|
|
{
|
|
|
int rowOffset = headerRows + int.Parse(Y.Value.ToString());
|
|
|
@@ -276,11 +238,21 @@ namespace UAS_MES_NEW.Query
|
|
|
// ---------- 8. 页脚 ----------
|
|
|
string pageFooter = $"第 {imageIndex} 页 / 共 {totalPages} 页";
|
|
|
newshe.PageSetup.SetFooter(1, pageFooter);
|
|
|
- // ---------- 9. 渲染为 PNG ----------
|
|
|
+
|
|
|
+ // ==================★ 优化点:提高渲染分辨率(核心改动) ==================
|
|
|
ImageOrPrintOptions options = new ImageOrPrintOptions();
|
|
|
options.ImageFormat = ImageFormat.Png;
|
|
|
- options.OnePagePerSheet = true;
|
|
|
+ options.OnePagePerSheet = true; // 保留:整页一张图
|
|
|
options.PrintingPage = PrintingPageType.Default;
|
|
|
+ // ★ 把默认 96 DPI 提高到 300 DPI,文字/表格瞬间变清晰(约放大3倍像素)
|
|
|
+ options.HorizontalResolution = 300;
|
|
|
+ options.VerticalResolution = 300;
|
|
|
+ // ★ 开启抗锯齿,边缘更平滑(18.x 支持,可选)
|
|
|
+ options.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
|
|
+ // ★ 文本渲染更清晰(可选)
|
|
|
+ options.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
|
|
|
+ // ==================★ 优化点结束 ==================
|
|
|
+
|
|
|
SheetRender sr = new SheetRender(newshe, options);
|
|
|
if (sr.PageCount > 0)
|
|
|
{
|
|
|
@@ -319,6 +291,7 @@ namespace UAS_MES_NEW.Query
|
|
|
//}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
else if (PDF.Checked)
|