如何使用后面的代码在xls表中添加水印? [英] how to add watermark in xls sheet using code behind ?

查看:127
本文介绍了如何使用后面的代码在xls表中添加水印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我能够使用流编写器和字符串生成器成功创建.xls文件,并且能够将其物理保存在磁盘上.现在,老板要求我在后台添加水印.我该怎么办??????
这是我的代码:

Hi,

I am able to create .xls file successfully using stream writer and string builder and I am able to save it physically on the disk. Now my boss asked me to add a watermark in the background. How can I do that ?????
here is my code:

<pre lang="c#">
public static void ExportToFile(string filename, string filepath, System.Data.DataTable dtResult, string webServerFileLink)
    {
        string sFlag = "Error";

        StreamWriter sw = new StreamWriter(filepath, false);
        StringBuilder dataToExport = new StringBuilder();
        sw.WriteLine(Convert.ToString(dataToExport));
        
        try
        {
            if (filename.Trim() != "" && filepath != "" && dtResult.Rows.Count != 0)
            {
                 dataToExport.Append("<table width=\"100%\">");
                dataToExport.Append("<tr>");
               
                foreach (DataColumn dCol in dtResult.Columns)
                {
                    dataToExport.Append("<td style=\"border:#ccc 1px dotted; height:40px; vertical-align:middle;text-align:center;min-width:100px; background-color:#D0EFF5;\">");
                    dataToExport.Append(HttpContext.Current.Server.HtmlEncode(dCol.ColumnName));
                    dataToExport.Append("</td>");
                    
                }
             

                dataToExport.Append("</tr>");

                foreach (DataRow dRow in dtResult.Rows)
                {
                    dataToExport.Append("<tr>");
                    foreach (object obj in dRow.ItemArray)
                    {
                        dataToExport.Append("<td style=\"border:#ccc 1px dotted;min-width:100px; vertical-align:middle;text-align:center;\">");
                        dataToExport.Append(HttpContext.Current.Server.HtmlEncode(obj.ToString()));
                        dataToExport.Append("</td>");
                      
                    }
                   
                    dataToExport.Append("</tr>");
                }

                dataToExport.Append("</table>");
                
            }
            sw.WriteLine(Convert.ToString(dataToExport));
            sFlag = "Success";

            sw.Close();
           

        }



        catch (Exception ex)
        {
            throw ex;
        }


       
      
    }  




请帮忙!




Please Help !

推荐答案

xls是Excel电子表格.我不确定它是否支持水印,它们通常存在于位图上.您发布的代码将创建一个表,该表与Excel无关,除非您没有显示将表转换为xls文件的代码.如果您确实有这样的库,那么我可能会怀疑它有可能做您想要的方法,因为它似乎无法直接与Excel一起使用.从您发布的代码很难说.使用Office的Micrsoft工具,您可以与.NET中的Office文件进行交互.如果根本没有水印,那么也许就是在那里.

但是,鉴于Excel文件不是位图,您添加的任何内容都可以删除最终用途.
An xls is an Excel spreadsheet. I am not sure it supports watermarks, they tend to exist on bitmaps. The code you posted creates a table, which has nothing to do with Excel, unless you have code you didn''t show that turns tables into an xls file. If you do have such a library, then it may have methods to do what you want, although I doubt it, as it does not seem to work with Excel directly. Hard to say from the code you posted. The Micrsoft Tools for Office let you interact with Office files in .NET. If watermarks exist at all, then perhaps that''s where you can do it.

But given that an Excel file is not a bitmap, anything you add, an end use can remove.


这篇关于如何使用后面的代码在xls表中添加水印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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