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

相关推荐
Panda__Panda1 小时前
docker项目打包演示项目(数字排序服务)
运维·javascript·python·docker·容器·c#
weixin_456904272 小时前
基于.NET Framework 4.0的串口通信
开发语言·c#·.net
Tiger_shl3 小时前
C# 预处理指令 (# 指令) 详解
开发语言·c#
sali-tec4 小时前
C# 基于halcon的视觉工作流-章45-网格面划痕
开发语言·算法·计算机视觉·c#
云草桑8 小时前
C#入坑JAVA 使用XXLJob
java·开发语言·c#
玉夏8 小时前
【每日算法C#】爬楼梯问题 LeetCode
算法·leetcode·c#
SunkingYang11 小时前
详细介绍C++中通过OLE操作excel时,一般会出现哪些异常,这些异常的原因是什么,如何来解决这些异常
c++·excel·解决方案·闪退·ole·异常类型·异常原因
Wu_hello_mi11 小时前
Excel使用教程笔记
笔记·excel
恶猫11 小时前
Polaris Officev9.9.12全功能解锁版
pdf·word·excel·ppt·office·办公·打工