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

相关推荐
曹牧9 小时前
C#:线程间操作无效,不是从创建控件线程访问
开发语言·c#
anlog17 小时前
ini文件读取,EXE同目录文件读取
c#·ini
rockey62718 小时前
AScript之编译递归函数
c#·.net·script·动态脚本
yue0081 天前
winform控件篇-按钮
c#
DevOpenClub1 天前
Markdown、HTML 和 PPT 如何稳定交付:文档转换任务的幂等发布流程
开发语言·前端·c#·html·powerpoint
软件黑马王子1 天前
3.单例模式问题1:构造函数
开发语言·单例模式·c#
软件黑马王子1 天前
4.单例模式问题2:重复挂载
开发语言·单例模式·c#
夏霞1 天前
c# 不支持的目标框架 解决方案
开发语言·c#
软件黑马王子1 天前
5.单例模式问题3:多线程问题
单例模式·前端框架·c#
geovindu1 天前
CSharp: Template Method Pattern
开发语言·后端·c#·.net·模板方法模式·行为模式