[C#] 纯文本查看 复制代码using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
// 窗口初始化
InitializeComponent();
ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
}
private void Form1_Load(object sender, EventArgs e)
{
// 打开Excel文件
using (ExcelPackage package = new ExcelPackage(new FileInfo("your_excel_file.xlsx")))
{
// 获取工作表
ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
// 检查B2单元格是否包含图片
bool hasImage = worksheet.Drawings.Any(d => d.From.Column == 2 && d.From.Row == 2 && d is OfficeOpenXml.Drawing.ExcelPicture);
if (hasImage)
{
MessageBox.Show("B2单元格包含图片。");
}
else
{
MessageBox.Show("B2单元格不包含图片。");
}
}
}
}
}
但不知道为什么,我把图片放在了B2单元格上就是识别不到图片,hasImage返回结果是false,无论是浮动在B2单元格上方还是嵌入到B2单元格中,都不能识别
[i]
求个大佬帮忙
源码和Excel附上
https://wwio.lanzoub.com/iLspc2cj8w2b