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

相关推荐
宝桥南山5 小时前
GitHub Models - 尝试一下使用GitHub Models
microsoft·ai·微软·c#·github·.netcore
实战编程7 小时前
Temu 插件导出 Excel 图片问题总结(SheetJS / ExcelJS)
excel
hixiong1238 小时前
C# OpenvinoSharp部署INSID3
开发语言·人工智能·ai·c#·openvinosharp
Data-Miner8 小时前
用DeepSeek V4做表:数以轻舟Agent让做Excel表像聊天一样简单
microsoft·excel
星辰徐哥8 小时前
Unity C#入门:变量的定义与访问权限(public/private)
unity·c#·lucene
leoufung9 小时前
LeetCode 30:Substring with Concatenation of All Words 题解(含 C 语言 uthash 实现)
c语言·leetcode·c#
hacker7079 小时前
Visual Studio安装教程(C#开发版)
ide·c#·visual studio
SKY -dada9 小时前
Understand 使用教程
开发语言·c#·流程图·软件构建·敏捷流程·代码复审·源代码管理
William_cl12 小时前
【C#/.NET 进阶】ASP.NET 架构与最佳实践:DI 依赖注入(IoC 核心)从入门到避坑
c#·asp.net·.net
武藤一雄12 小时前
WPF:MessageBox系统消息框
前端·microsoft·c#·.net·wpf