|
@@ -181,7 +181,9 @@ namespace UAS_MES_NEW.Query
|
|
|
for (int s = newshe.Shapes.Count - 1; s >= 0; s--)
|
|
for (int s = newshe.Shapes.Count - 1; s >= 0; s--)
|
|
|
{
|
|
{
|
|
|
Aspose.Cells.Drawing.Shape shape;
|
|
Aspose.Cells.Drawing.Shape shape;
|
|
|
- try { shape = newshe.Shapes[s]; }
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ shape = newshe.Shapes[s];
|
|
|
|
|
+ }
|
|
|
catch { continue; }
|
|
catch { continue; }
|
|
|
int topRow = shape.UpperLeftRow;
|
|
int topRow = shape.UpperLeftRow;
|
|
|
bool isHeaderShape = topRow < headerRows;
|
|
bool isHeaderShape = topRow < headerRows;
|
|
@@ -191,6 +193,39 @@ namespace UAS_MES_NEW.Query
|
|
|
try { newshe.Shapes.RemoveAt(s); }
|
|
try { newshe.Shapes.RemoveAt(s); }
|
|
|
catch { shape.IsHidden = true; }
|
|
catch { shape.IsHidden = true; }
|
|
|
}
|
|
}
|
|
|
|
|
+ else {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ // 1. 启用文本自动换行
|
|
|
|
|
+ shape.IsTextWrapped = true;
|
|
|
|
|
+
|
|
|
|
|
+ Console.WriteLine(shape.Text);
|
|
|
|
|
+ // 2. 获取文本对齐对象并设置内边距
|
|
|
|
|
+ if (shape.TextBody != null && shape.TextBody.TextAlignment != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ var textAlign = shape.TextBody.TextAlignment;
|
|
|
|
|
+ textAlign.LeftMarginPt = 1;
|
|
|
|
|
+ textAlign.RightMarginPt = 1;
|
|
|
|
|
+ textAlign.TopMarginPt = 1;
|
|
|
|
|
+ textAlign.BottomMarginPt = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 设置文本对齐方式
|
|
|
|
|
+ shape.TextVerticalAlignment = TextAlignmentType.Left;
|
|
|
|
|
+ shape.TextHorizontalAlignment = TextAlignmentType.Left;
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 自动调整形状大小以适应文本(如果形状允许)
|
|
|
|
|
+ if (shape.TextBody != null && shape.TextBody.TextAlignment != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ shape.TextBody.TextAlignment.TextHorizontalOverflow = TextOverflowType.Ellipsis;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ // 某些形状可能不支持所有属性,忽略异常
|
|
|
|
|
+ Console.WriteLine($"Shape优化失败: {ex.Message}");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
// ---------- 4. 清空非本页单元格内容 ----------
|
|
// ---------- 4. 清空非本页单元格内容 ----------
|
|
|
for (int r = 0; r < totalRows; r++)
|
|
for (int r = 0; r < totalRows; r++)
|
|
@@ -209,9 +244,20 @@ namespace UAS_MES_NEW.Query
|
|
|
// ---------- 6. 页面设置 ----------
|
|
// ---------- 6. 页面设置 ----------
|
|
|
int printMaxRow = newshe.Cells.MaxDataRow;
|
|
int printMaxRow = newshe.Cells.MaxDataRow;
|
|
|
for (int p = 0; p < newshe.Pictures.Count; p++)
|
|
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++)
|
|
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;
|
|
int newTotalRows = printMaxRow + 1;
|
|
|
int pageHeight = headerRows + dataRowsPerPage;
|
|
int pageHeight = headerRows + dataRowsPerPage;
|
|
|
int printEndRow = Math.Max(newTotalRows, pageHeight);
|
|
int printEndRow = Math.Max(newTotalRows, pageHeight);
|