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

相关推荐
布呐呐na27 分钟前
C#基础篇(10)集合类之列表
开发语言·c#
UrbanJazzerati44 分钟前
Excel 使用中的“坑”:拆分与合并列的陷阱及解决方案
excel
唐青枫2 小时前
C#.NET serilog 详解
c#·.net
KeThink13 小时前
国民经济行业分类 GB/T 4754—2017 (PDF和exce版本)
pdf·excel
_oP_i13 小时前
Excel 的多线程特性
excel
开开心心_Every16 小时前
全能视频处理工具介绍说明
开发语言·人工智能·django·pdf·flask·c#·音视频
86Eric16 小时前
C# 入门学习教程(二)
c#·操作符·语句
V1ncent Chen17 小时前
Excel基础:数据查看
excel
simonkimi18 小时前
解决无法在Cursor中使用C# Dev Kit的问题
c#·cursor
枯萎穿心攻击1 天前
ECS由浅入深第三节:进阶?System 的行为与复杂交互模式
开发语言·unity·c#·游戏引擎