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

相关推荐
Abigail_chow3 小时前
EXCEL如何快速批量给两字姓名中间加空格
windows·microsoft·excel·学习方法·政务
绿荫阿广5 小时前
互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(五):使用.NET为树莓派开发Wifi配网功能
c#·.net
ou.cs7 小时前
c# :this() 和 :base()区别
开发语言·c#
汪小白JIY11 小时前
【C#】异步和多线程
c#·thread·async·task·threapool
宝桥南山12 小时前
DeepSeek - 尝试一下GitHub Models中的DeepSeek
microsoft·ai·微软·c#·github·.net
xiaohezi14 小时前
Rag chunk 之:Excel 文档解析
excel
weixin_4723394618 小时前
python批量解析提取word内容到excel
python·word·excel
lljss202019 小时前
C# 一个解决方案放一个dll项目,一个dll测试项目 ,调试dll项目的源码
c#
ghost1431 天前
C#学习第27天:时间和日期的处理
开发语言·学习·c#
jason成都1 天前
c#压缩与解压缩-SharpCompress
开发语言·c#