2
我試圖通過EPPlus添加一些圖片在Excel 2007工作簿但是當我使用 From.Column和From.Row我打開生成的XLSX文件時出現此錯誤:EPPlus給AddPicture導致Excel 2007年文件損壞
在此先感謝您的幫助。 這裏是我的代碼:
foreach (DataRow row in table.Rows)
{
for (int i = 0; i < row.ItemArray.Length; i++)
{
if (!row.ItemArray[i].ToString().Contains(';'))
{
wrksht.Cells[_rows, i + 1].Value = row.ItemArray[i];
}
else
{
if (row.ItemArray[i].ToString().Split(';')[0] == "img")
{
if (File.Exists(row.ItemArray[i].ToString().Split(';')[1]))
{
System.Drawing.Image img = System.Drawing.Image.FromFile(row.ItemArray[i].ToString().Split(';')[1]);
OfficeOpenXml.Drawing.ExcelPicture pic = wrksht.Drawings.AddPicture(
(_rows + i * new Random(_rows + i).Next()).ToString(), img
);
pic.SetSize(img.Width + 5, img.Height + 5);
pic.From.Column = i + 1;
pic.From.Row = _rows;
pic.From.RowOff = ExcelHelper.Pixel2MTU(1);
pic.From.ColumnOff = ExcelHelper.Pixel2MTU(1);
}
}
}
}
_rows++;
}