我正在将数据插入Excel并尝试使用图表对象进行range.CopyPicture
。我在图片中看到一些随机的粗体边框,这些边框是从Excel工作表中提取为PNG的。
workBook = objApp.Workbooks.Open(newPath);
workBook.CheckCompatibility = false;
Worksheet ws = workBook.Sheets["sheet1"];
Excel.Range last =
ws.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell,
Type.Missing);
Excel.Range r = workBook.Sheets["sheet1"].Range["A1:"+ last];
r.CopyPicture(Excel.XlPictureAppearance.xlScreen,
Excel.XlCopyPictureFormat.xlPicture);
ChartObject chartObj = ws.ChartObjects().Add(r.Left, r.Top,
r.Width, r.Height);
chartObj.Activate();
Chart chart = chartObj.Chart;
chart.Paste();
chart.Export(@"C:\\Documents\Docs\test" + ".png", "PNG");
// Clean up.
workBook.Save();
workBook.Close();
我的猜测是Excel在插入数据并从中获取图片时会创建一些随机边框。但是,将数据插入Excel并保存后,在Excel中看不到边框。