作成日: 2024/07/17 最終更新日: 2024/07/17
文書種別
不具合
状況
修正済み
詳細
帳票出力時、グループ化によって画像セルが結合される際、画像がセルの中央ではなく上部に配置されます。
回避方法
この問題はバージョン7.1.3で修正されました。
※修正版を適用しない場合の回避方法は以下の通りです。
ProcessTemplateメソッドの実行後に下記の処理を呼び出す方法にて回避できます。
※修正版を適用しない場合の回避方法は以下の通りです。
ProcessTemplateメソッドの実行後に下記の処理を呼び出す方法にて回避できます。
static void Main(string[] args)
{
・・・
workbook.ProcessTemplate();
ProcessShapeWithCellAlignment(workbook); //回避策
workbook.Save("test.xlsx");
}
//回避策
private static void ProcessShapeWithCellAlignment(Workbook workbook)
{
foreach (var worksheet in workbook.Worksheets)
{
foreach (var shape in worksheet.Shapes)
{
var leftTopCell = shape.TopLeftCell;
var rightBottomCell = shape.BottomRightCell;
var entireMergeArea = leftTopCell?.EntireMergeArea;
if (leftTopCell != null && rightBottomCell != null &&
((leftTopCell.Row == rightBottomCell.Row &&
leftTopCell.Column == rightBottomCell.Column) ||
(entireMergeArea != null && rightBottomCell.Row >= entireMergeArea.Row &&
rightBottomCell.Row <= entireMergeArea.LastRow &&
rightBottomCell.Column >= entireMergeArea.Column &&
rightBottomCell.Column <= entireMergeArea.LastColumn)))
{
var rect = CellInfo.GetAccurateRangeBoundary(entireMergeArea != null ? entireMergeArea : leftTopCell);
if (leftTopCell.HorizontalAlignment == HorizontalAlignment.Left)
{
// Adjust the position of the shape to align left.
shape.LeftInPixel = rect.Left;
}
else if (leftTopCell.HorizontalAlignment == HorizontalAlignment.Center)
{
// adjust the position of the shape to center
shape.LeftInPixel = rect.Left + (rect.Right - rect.Left - shape.WidthInPixel) / 2;
}
else if (leftTopCell.HorizontalAlignment == HorizontalAlignment.Right)
{
// adjust the position of the shape to right
shape.LeftInPixel = rect.Right - shape.WidthInPixel;
}
if (leftTopCell.VerticalAlignment == VerticalAlignment.Top)
{
// adjust the position of the shape to top
shape.TopInPixel = rect.Top;
}
else if (leftTopCell.VerticalAlignment == VerticalAlignment.Center)
{
// adjust the position of the shape to center
shape.TopInPixel = rect.Top + (rect.Bottom - rect.Top - shape.HeightInPixel) / 2;
}
else if (leftTopCell.VerticalAlignment == VerticalAlignment.Bottom)
{
// adjust the position of the shape to bottom
shape.TopInPixel = rect.Bottom - shape.HeightInPixel;
}
}
}
}
}