Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获取Zen条码框架生成的图像并将其导出到excel_C#_Excel_Visual Studio - Fatal编程技术网

C# 如何获取Zen条码框架生成的图像并将其导出到excel

C# 如何获取Zen条码框架生成的图像并将其导出到excel,c#,excel,visual-studio,C#,Excel,Visual Studio,我有一个问题,当前无法将Zen Barcode framework在PictureBox中创建的图像插入Excel。 到目前为止,我只想将其保存为jpeg文件,但我想在单击“转换为Excel”按钮时将生成的条形码和二维码插入Microsoft Excel。我现在面临的唯一问题是,在生成条形码和二维码后,我无法将其导出到Microsoft Excel,但我可以获取输入到Excel中的内容将“文本框”设置为excel 公共部分类表单1:表单 { 公共对象SaveFileDialog1{get;pr

我有一个问题,当前无法将Zen Barcode framework在
PictureBox
中创建的图像插入Excel。
到目前为止,我只想将其保存为jpeg文件,但我想在单击“转换为Excel”按钮时将生成的条形码和二维码插入Microsoft Excel。
我现在面临的唯一问题是,在生成条形码和二维码后,我无法将其导出到Microsoft Excel,但我可以获取输入到Excel中的内容将“文本框”设置为excel


公共部分类表单1:表单
{
公共对象SaveFileDialog1{get;private set;}
//位图;
公共表格1()
{
初始化组件();
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{
Zen.Barcode.Code128BarcodeDraw Barcode=Zen.Barcode.BarcodeDrawFactory.Code128带校验和;
pictureBox.Image=barcode.Draw(Barcodetxt.Text,50);
}
私有无效btnQR_单击(对象发送者,事件参数e)
{
Zen.Barcode.CodeQrBarcodeDraw qrcode=Zen.Barcode.BarcodeDrawFactory.CodeQr;
pictureBox1.Image=qrcode.Draw(QRCodetxt.Text,50);
}
私有void Form1\u加载(对象发送方、事件参数e)
{
}
私有void btnexcel\u单击(对象发送者,事件参数e)
{
string file=“D:/newdoc.xls”;
工作簿=新工作簿();
工作表=新工作表(“标签打印”);
worksheet.Cells[1,3]=新单元格(Barcodetxt.Text);
worksheet.Cells[2,5]=新单元格(QRCodetxt.Text);
位图bm=默认值(位图);
bm=新位图(pictureBox1.Width,pictureBox1.Height);
System.Windows.Forms.Clipboard.SetDataObject(bm,false);
//worksheet.Cells[3,8]=新单元格(pictureBox.Image);
//worksheet.Cells[1,2]=新单元格(pictureBox.Image);
//工作表.Cells[1,3]=新单元格(pictureBox1.Image);
workbook.Worksheets.Add(工作表);workbook.Save(文件);
//打开xls文件
工作簿簿=工作簿.Load(文件);
工作表=书本。工作表[0];
//遍历单元格
//foreach(成对,单元格>表格单元格中的单元格)
{
//dgvCells[cell.Left.Right,cell.Left.Left].Value=cell.Right.Value;
}
//按索引遍历行

对于(int rowIndex=sheet.Cells.FirstRowIndex;rowIndex问题出在哪一部分:将条形码合并到图像中还是将一些图像插入excel?问题是我似乎无法将图片框中生成的条形码和QR码导出到excel,我想知道为什么要将图像保存到相同的名称,甚至根本不保存它们。但是他真正的问题是:你在哪里尝试将它们插入excel?或者为什么要将一个空图像放入剪贴板?例如
public partial class Form1: Form
{
    public object SaveFileDialog1 { get; private set; }

    // Bitmap qrCodeImage;

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Zen.Barcode.Code128BarcodeDraw barcode = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
        pictureBox.Image = barcode.Draw(Barcodetxt.Text, 50);
    }

    private void btnQR_Click(object sender, EventArgs e)
    {
        Zen.Barcode.CodeQrBarcodeDraw qrcode = Zen.Barcode.BarcodeDrawFactory.CodeQr;
        pictureBox1.Image = qrcode.Draw(QRCodetxt.Text, 50);
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void btnexcel_Click(object sender, EventArgs e)
    {
        string file = "D:/newdoc.xls";
        Workbook workbook = new Workbook();
        Worksheet worksheet = new Worksheet("Label Pritting ");
        worksheet.Cells[1, 3] = new Cell(Barcodetxt.Text);
        worksheet.Cells[2, 5] = new Cell(QRCodetxt.Text);
        Bitmap bm = default(Bitmap);

        bm = new Bitmap(pictureBox1.Width, pictureBox1.Height);

        System.Windows.Forms.Clipboard.SetDataObject(bm, false);

        //worksheet.Cells[3, 8] = new Cell(pictureBox.Image);
        //worksheet.Cells[1, 2] = new Cell(pictureBox.Image);
        // worksheet.Cells[1, 3] = new Cell(pictureBox1.Image);
        workbook.Worksheets.Add(worksheet); workbook.Save(file);

        // open xls file
        Workbook book = Workbook.Load(file);
        Worksheet sheet = book.Worksheets[0];

        // traverse cells
        //foreach (Pair, Cell > cell in sheet.Cells)
        {
            //  dgvCells[cell.Left.Right, cell.Left.Left].Value = cell.Right.Value;
        }

        // traverse rows by Index
        for (int rowIndex = sheet.Cells.FirstRowIndex; rowIndex <= sheet.Cells.LastRowIndex; rowIndex++)
        {
            Row row = sheet.Cells.GetRow(rowIndex);
            for (int colIndex = row.FirstColIndex; colIndex <= row.LastColIndex; colIndex++)
            {
                Cell cell = row.GetCell(colIndex);
            }
        }
    }

    private void pictureBox_Click(object sender, EventArgs e)
    {

    }

    private void pictureBox1_Click(object sender, EventArgs e)
    {

    }

    private void Saveqrcodebtn_Click(object sender, EventArgs e)
    {
        string saveFileName;
        SaveFileDialog saveDialog = new SaveFileDialog();
        saveDialog.DefaultExt = "jpg";
        saveDialog.Filter = "jpeg|*.jpg";
        // saveDialog.FileName = saveFileName;
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        if (saveDialog.ShowDialog() == DialogResult.OK)
        {
            try
            {
                saveFileName = saveDialog.FileName;
                pictureBox.Image.Save(saveFileName);
                pictureBox1.Image.Save(saveFileName);

                MessageBox.Show(saveFileName + " Save Complete", "Complete", MessageBoxButtons.OK);
            }
            catch
            {
                MessageBox.Show("Error file is open/in use");
            }
            pictureBox1.Image = null;
        }
    }

    private void Barcodebtn_Click(object sender, EventArgs e)
    {
        string saveFileName;
        SaveFileDialog saveDialog = new SaveFileDialog();
        saveDialog.DefaultExt = "jpg";
        saveDialog.Filter = "jpeg|*.jpg";
        // saveDialog.FileName = saveFileName;
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        if (saveDialog.ShowDialog() == DialogResult.OK)
        {
            try
            {
                saveFileName = saveDialog.FileName;
                pictureBox.Image.Save(saveFileName);
                pictureBox1.Image.Save(saveFileName);

                MessageBox.Show(saveFileName + " Save Complete", "Complete", MessageBoxButtons.OK);
            }
            catch
            {
                MessageBox.Show("Error file is open/in use");
            }
            pictureBox1.Image = null;
        }
    }
}