在本地测试时,剪贴板中的数据为空。只需在Aspx页面的@Page指令中添加AspCompat =“ true”即可读取剪贴板中的图片。在操作过程中输入clipbrd并打开剪贴板,可以看到剪贴板中有excel图片。
当2.发布到iis时,如果未添加AspCompat =“ true”,则剪贴板读取的数据仍然为空;添加后,请求的剪贴板数据将失败。错误! !当我在服务器上打开剪贴板时,根本找不到任何图片。使用网民提供的数据在单个线程中读取剪贴板中的数据也是一个错误。我认为原因是剪贴板是System.Windows.Forms下的一个类,在C / S表单程序中根本没有问题;并且在网络中,它可能是iis或类似的保护机制,这使得无法操作Clipboard类。

3.工作了两天,但是找不到用Excel在excel中读取图片的解决方案。因此,只能使用NPOI。

//加载excel表格
Stream stream = new FileStream(filePath, FileMode.OpenOrCreate);
XSSFWorkbook NPOIWorkBook = new XSSFWorkbook(stream);
stream.Dispose();
//根据index加载带有图片的sheet
XSSFSheet iSheet = (XSSFSheet)NPOIWorkBook.GetSheetAt(index);
try
{
var documentPartList = iSheet.GetRelations();
foreach (var documentPart in documentPartList)
{
if (documentPart is XSSFDrawing)
{
var drawing = (XSSFDrawing)documentPart;
var shapeList = drawing.GetShapes();
foreach (var shape in shapeList)
{
if (shape is XSSFPicture)
{
XSSFPicture picture = (XSSFPicture)shape;
byte[] bytes = picture.PictureData.Data;
using (MemoryStream ms = new MemoryStream(bytes))
{
using (Bitmap map = new Bitmap(ms))
{
string path = "/" + DateTime.Now.ToString("yyyyMMddHHmmssff") + ".jpg";
map.Save(Server.MapPath(path), System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
}
}
}
}
catch (Exception ex)
{
}
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/shumachanpin/article-356283-1.html
10万一年下来搞不好就只有3万本金了