callm 2 дней назад
Родитель
Сommit
5b1cdb42ee
1 измененных файлов с 42 добавлено и 24 удалено
  1. 42 24
      UAS_MES_ZKLH/FunctionCode/Query/Query_SOP.cs

+ 42 - 24
UAS_MES_ZKLH/FunctionCode/Query/Query_SOP.cs

@@ -135,7 +135,20 @@ namespace UAS_MES_NEW.Query
                             const int headerRows = 3;                              // 表头行数(每页都保留)
                             int dataRowsPerPage = int.Parse(RowCount.Value.ToString());
 
-                            int totalRows = she.Cells.MaxDataRow + 1;
+                            // ★ 关键修复①:计算"内容最大行"时必须包含图片和形状的底部锚点行
+                            // 图片/形状不影响 Cells.MaxDataRow,只看单元格会把底部图片切掉
+                            int contentMaxRow = she.Cells.MaxDataRow;
+                            for (int p = 0; p < she.Pictures.Count; p++)
+                            {
+                                if (she.Pictures[p].LowerRightRow > contentMaxRow)
+                                    contentMaxRow = she.Pictures[p].LowerRightRow;
+                            }
+                            for (int s = 0; s < she.Shapes.Count; s++)
+                            {
+                                if (she.Shapes[s].LowerRightRow > contentMaxRow)
+                                    contentMaxRow = she.Shapes[s].LowerRightRow;
+                            }
+                            int totalRows = contentMaxRow + 1;
                             int totalDataRows = Math.Max(totalRows - headerRows, 0);
                             int totalPages = (int)Math.Ceiling(totalDataRows / (double)dataRowsPerPage);
                             if (totalPages == 0) totalPages = 1;
@@ -159,7 +172,6 @@ namespace UAS_MES_NEW.Query
                                 int dataEndRow = Math.Min(headerRows + (page + 1) * dataRowsPerPage - 1, totalRows - 1);
 
                                 // ---------- 2. 按页过滤原表图片(Pictures) ----------
-                                // 保留:表头区图片 + 顶部锚点落在本页数据区的图片
                                 for (int p = newshe.Pictures.Count - 1; p >= 0; p--)
                                 {
                                     Aspose.Cells.Drawing.Picture pic = newshe.Pictures[p];
@@ -173,7 +185,6 @@ namespace UAS_MES_NEW.Query
                                 }
 
                                 // ---------- 3. 按页过滤原表形状(Shapes:文本框/箭头/连接线等) ----------
-                                // 防止"扭力扳手"这类文本框说明从第1页残留到第2页
                                 for (int s = newshe.Shapes.Count - 1; s >= 0; s--)
                                 {
                                     Aspose.Cells.Drawing.Shape shape = newshe.Shapes[s];
@@ -186,12 +197,12 @@ namespace UAS_MES_NEW.Query
                                     }
                                 }
 
-                                // ---------- 4. 清空非本页单元格内容(防止表格/文字残留) ----------
+                                // ---------- 4. 清空非本页单元格内容 ----------
                                 for (int r = 0; r < totalRows; r++)
                                 {
-                                    if (r < headerRows) continue;                                   // 表头保留
-                                    if (r >= dataStartRow && r <= dataEndRow) continue;            // 本页数据保留
-                                    newshe.Cells.ClearRange(r, 0, r, lastColIndex);                // 清空该行内容与样式
+                                    if (r < headerRows) continue;
+                                    if (r >= dataStartRow && r <= dataEndRow) continue;
+                                    newshe.Cells.ClearRange(r, 0, r, lastColIndex);
                                 }
 
                                 // ---------- 5. 删除非本页整行 ----------
@@ -203,8 +214,27 @@ namespace UAS_MES_NEW.Query
                                 }
 
                                 // ---------- 6. 页面设置 ----------
-                                int newTotalRows = newshe.Cells.MaxDataRow + 1;
-                                newshe.PageSetup.PrintArea = $"A1:{lastColLetter}{newTotalRows}";
+                                // ★ 关键修复②:PrintArea 必须覆盖临时表中图片/形状延伸到的最大行
+                                // 不能只用 Cells.MaxDataRow + 1,否则底部图片被截断
+                                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;
+                                }
+                                for (int s = 0; s < newshe.Shapes.Count; s++)
+                                {
+                                    if (newshe.Shapes[s].LowerRightRow > printMaxRow)
+                                        printMaxRow = newshe.Shapes[s].LowerRightRow;
+                                }
+                                int newTotalRows = printMaxRow + 1;
+                                if (i == 0)
+                                {
+                                    newshe.PageSetup.PrintArea = $"A1:{lastColLetter}{25}";
+                                }
+                                else {
+                                    newshe.PageSetup.PrintArea = $"A1:{lastColLetter}{newTotalRows}";
+                                }
                                 newshe.PageSetup.CenterHorizontally = true;
                                 newshe.PageSetup.CenterVertically = true;
                                 newshe.PageSetup.LeftMargin = 2;
@@ -218,22 +248,9 @@ namespace UAS_MES_NEW.Query
                                 // ---------- 7. 插入水印(额外图片,坐标映射到压缩后本页) ----------
                                 if (File.Exists(PrintPath.Text))
                                 {
-                                    int wmRowLocal = -1;
-                                    if (wmRowGlobal < headerRows)
-                                    {
-                                        wmRowLocal = wmRowGlobal;                              // 表头区直接用
-                                    }
-                                    else if (wmRowGlobal >= dataStartRow && wmRowGlobal <= dataEndRow)
-                                    {
-                                        wmRowLocal = headerRows + (wmRowGlobal - dataStartRow); // 数据行换算
-                                    }
-
-                                    if (wmRowLocal >= 0 && wmRowLocal < newTotalRows)
-                                    {
-                                        newshe.Pictures.Add(wmRowLocal, wmCol, PrintPath.Text);
-                                    }
+                                    int rowOffset = headerRows + int.Parse(Y.Value.ToString());
+                                    newshe.Pictures.Add(rowOffset, int.Parse(X.Value.ToString()), PrintPath.Text);
                                 }
-
                                 // ---------- 8. 页脚 ----------
                                 string pageFooter = $"第 {imageIndex} 页 / 共 {totalPages} 页";
                                 newshe.PageSetup.SetFooter(1, pageFooter);
@@ -286,6 +303,7 @@ namespace UAS_MES_NEW.Query
                             OperatResult.AppendText(ex.Message + ex.StackTrace);
                         }
                     }
+
                 }
             }
             else if (PDF.Checked)