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就可以了

相关推荐
花北城3 小时前
【C#】ABP框架服务端开发
开发语言·c#·abp
xiaoshuaishuai85 小时前
C# vCenter跨云迁移的核心问题
开发语言·c#
旧物有情5 小时前
C#异步编程
网络·rpc·c#
影寂ldy7 小时前
C# 三大内置委托(Action / Func / Predicate)+ Lambda
c++·算法·c#
不恋水的雨9 小时前
easyexcel快速填充大数据量不覆盖后面的行解决方式
java·excel·poi
小满Autumn11 小时前
固高GTS运动控制卡 — C#开发完全指南
c#·.net·上位机·运动控制卡
影寂ldy11 小时前
C# 多播委托
前端·javascript·c#
靖待11 小时前
【解决方法】python写Excel单元格截断长文本
python·excel·解决方法
The Sheep 202312 小时前
C#多线程学习
开发语言·学习·c#
我要打打代码12 小时前
C# 扩展方法
开发语言·c#