使用OfficeOpenXml / epplus添加Excel水印 [英] Adding Excel Watermark using OfficeOpenXml / epplus

查看:242
本文介绍了使用OfficeOpenXml / epplus添加Excel水印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题。.
我在Windows文件夹中有一组excel文件,需要使用c#对其进行水印处理。我已经在使用epplus。
是否可以使用epplus向Excel添加水印?
任何其他想法都值得赞赏。
谢谢

Here's my problem.. I have a set of excel files in windows folder that needs to be watermarked using c#. I am already using epplus. Is there any option to add watermark to excel using epplus?. Any other ideas is much appreciated. Thanks

推荐答案

找到了答案……下面是有效的代码块。 / p>

Found the answer... below is the working code block.. may help someone..

using System;
using System.Resources;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Configuration;
using VBIDE = Microsoft.Vbe.Interop;
using System.Runtime.InteropServices;
using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.Drawing;
using OfficeOpenXml.Style;

    private void button1_Click(object sender, EventArgs e)
            {
                Excel.Application xlApp;
                Excel.Workbook xlWorkBook;
                Excel.Worksheet xlWorkSheet;
                object misValue = System.Reflection.Missing.Value;

                xlApp = new Excel.Application();
                xlWorkBook = xlApp.Workbooks.Open(filePath.Text, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);


                foreach (Microsoft.Office.Interop.Excel.Worksheet wSheet in xlWorkBook.Worksheets)
                {
                    //Messagebox.show(wSheet.Name.ToString());
                    wSheet.SetBackgroundPicture("http://localhost/QA_red.png");


                }

                xlApp.Caption = "QA Tested";

                xlWorkBook.Close(true, misValue, misValue);
                xlApp.Quit();

                releaseObject(xlWorkSheet);
                releaseObject(xlWorkBook);
                releaseObject(xlApp);
            }

private void releaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch (Exception ex)
            {
                obj = null;
                MessageBox.Show("Unable to release the Object " + ex.ToString());
            }
            finally
            {
                GC.Collect();
            }
        }

这篇关于使用OfficeOpenXml / epplus添加Excel水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆