gpt4 book ai didi

c# - 查找左上角单元格的坐标?使用 EPPlus

转载 作者:行者123 更新时间:2023-11-30 12:12:48 25 4
gpt4 key购买 nike

我正在尝试将图像映射到 excel 电子表格中,我需要找到当前单元格的坐标是什么?

目前我的代码遍历每个单元格,直到它在 excel 中找到一个匹配的标签,它知道这是放置图片的单元格。

我有单元格,但我不知道如何获取单元格的顶部和左侧属性?

foreach (ExcelRangeBase cell in range1)
{

}

请帮忙!

提前致谢。

最佳答案

int row = cellAddress.Start.Row;
int column = cellAddress.Start.Column;


if (mCellsResult.Count() > 0)
{
var mCells = mCellsResult.First();

//if the cell and the merged cell do not share a common start address then skip this cell as it's already been covered by a previous item
if (mCells.Start.Address != cellAddress.Start.Address)
continue;

if (mCells.Start.Column != mCells.End.Column)
{
colSpan += mCells.End.Column - mCells.Start.Column;
}

if (mCells.Start.Row != mCells.End.Row)
{
rowSpan += mCells.End.Row - mCells.Start.Row;
}
}
double height = 0, width = 0;
for (int h = 0; h < rowSpan; h++)
{
height += xlWorkSeet1[k].Row(row + h).Height;
}
for (int w = 0; w < colSpan; w++)
{
width += xlWorkSeet1[k].Column(column + w).Width;
}

double pointToPixel = 0.75;

height /= pointToPixel;
width /= 0.1423;


picture = xlWorkSeet1[k].Drawings.AddPicture(System.Guid.NewGuid().ToString() + row.ToString() + column.ToString(), image);
picture.From.Column = column - 1;
picture.From.Row = row - 1;
picture.SetSize((int)width, (int)height);

关于c# - 查找左上角单元格的坐标?使用 EPPlus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12856646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com