winform 加载 office excel 插入QRCode图片如何设定位置

需求:winform 加载 office excel 并加载QRCode图片,但是每台PC打印出来QRCode位置都不太一样,怎么办呢?

我的办法:

1、在sheet中插入一个 textbox ,改名 qrcode (这个名字随便设置)

2、判断sheet中是否存在名字为qrcode 的textbox

cs 复制代码
//怎么加载excel,代码就省略了

bool _isexistQRCodeTextBox = false; //sheet中是否存在qrcode 的 textbox
if(sheet.Shapes.Count > 0)
{
    for (int _i = 1; _i <= sheet.Shapes.Count; _i++)
    {
        if (sheet.Shapes.Item(_i).Name == "qrcode")
        {
            _isexistQRCodeTextBox = true;
            break;
        }
    }
}
if (_isexistQRCodeTextBox)
{
    var xlsqrcode = sheet.TextBoxes("qrcode") as Microsoft.Office.Interop.Excel.TextBox;
    xlsqrcode.Visible = false;
    PicTop = Convert.ToSingle(xlsqrcode.Top);
    PicLeft = Convert.ToSingle(xlsqrcode.Left);

    var PicWidth = Convert.ToSingle(xlsqrcode.Width);
    var PicHeight = Convert.ToSingle(xlsqrcode.Height);
    //qrfilename是二维码图片的路径+图片文件名
    sheet.Shapes.AddPicture(qrFileName, Microsoft.Office.Core.MsoTriState.msoTrue, 
      Microsoft.Office.Core.MsoTriState.msoTrue, PicLeft, PicTop, PicWidth, PicHeight);
                       
}

这样插入一个textbox,就可以在每台PC的excel中移动 textbox就可以了

相关推荐
MyBFuture几秒前
C#表格与定时器实战技巧
开发语言·windows·c#·visual studio
feifeigo12335 分钟前
基于C#实现即时通讯工具
开发语言·c#
程序猿多布42 分钟前
C# 密封类、密封方法、密封属性、密封事件、密封索引器
c#
张人玉1 小时前
西门子 S7 PLC 通信 WPF 应用分析笔记
笔记·c#·wpf·plc
刘97531 小时前
【第22天】22c#今日小结
开发语言·c#
张人玉1 小时前
整合 Sugar ORM 连接 SQLite 数据库到 WPF 折线图项目
数据库·sqlite·c#·wpf
智航GIS1 小时前
9.3 Excel 自动化
python·自动化·excel
SunnyDays10112 小时前
使用 C# 将 Excel 转换为 Markdown 表格(含单文件与批量转换)
c#·excel转markdown
骑着蜗牛闯宇宙2 小时前
TP8上传Excel地址数据批量标注到高德地图
数据库·php·excel