就经过下面简单的把文件流导入workbook,然后再导出到另外一个新建的文件之后,就会出现下面图片的移位情况,请问有什么方法解决吗?
刚成为程序员,注册了这个网站ID,没多少分,抱歉了
string tempPath2 = outputTextBox.Text;
XSSFWorkbook wk_insert = new XSSFWorkbook();
using (FileStream fs2 = File.Open(tempPath2, FileMode.Open, FileAccess.Read, FileShare.Read))
{
wk_insert = new XSSFWorkbook(fs2);
fs2.Close();
}
if (File.Exists("d:\\temp.xlsx"))
{
File.Delete("d:\\temp.xlsx");
}
using (FileStream fs3 = File.OpenWrite("d:\\temp.xlsx"))
{
wk_insert.Write(fs3);//向打开的这个xls文件中写入并保存。
fs3.Close();
}
导入前:
导入后:
这个文件流是什么东西?
// 插入图片
MemoryStream ms = new MemoryStream();
snapShot.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);//拷贝到内存中
byte[] bytes = ms.ToArray();
int pictureIndex = hssfWorkbook.AddPicture(bytes, PictureType.JPEG);
HSSFPatriarch patriarch = (HSSFPatriarch)hssfSheet.CreateDrawingPatriarch();
// HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 300, 200, 5, 0, 10, 10);
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 260, 175, 0, 5, 7, 23);
HSSFPicture picture = (HSSFPicture)patriarch.CreatePicture(anchor, pictureIndex);
我都是这么插入图片到excel里的