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

相关推荐
hmywillstronger15 分钟前
【Excel】【VBA】根据内容调整打印区域
android·excel
code_shenbing37 分钟前
WPF 实现虚拟键盘
c#·wpf
oh,huoyuyan5 小时前
火语言RPA--Excel删除内容
excel·rpa
软件黑马王子6 小时前
C#初级教程(4)——流程控制:从基础到实践
开发语言·c#
失败尽常态5239 小时前
用Python实现Excel数据同步到飞书文档
python·excel·飞书
水煮庄周鱼鱼11 小时前
C# 入门简介
开发语言·c#
软件黑马王子12 小时前
Unity游戏制作中的C#基础(6)方法和类的知识点深度剖析
开发语言·游戏·unity·c#
Nicole Potter13 小时前
请说明C#中的List是如何扩容的?
开发语言·面试·c#
gu2014 小时前
c#编程:学习Linq,重几个简单示例开始
开发语言·学习·c#·linq
杜大哥16 小时前
如何在WPS打开的word、excel文件中,使用AI?
人工智能·word·excel·wps