随笔 - 21  文章 - 0  评论 - 8 
  2011年1月10日
<asp:CustomValidator ID="CustomvalidatorTCs" runat="server" Font-Bold="True"               Display="Dynamic" OnServerValidate="IAgreeCheck"  EnableClientScript="true" Text="<img src='../Common/Images/left_arrow.gif' />" ClientValidationFunction="iAgreeCheck"                                        ValidationGroup="OEGroup"></asp:CustomValidator>


posted @ 2011-01-10 23:50 潘安+宋玉 阅读(74) 评论(0) 编辑
  2009年12月20日

专门针对Excel2007的读写操作,首先想到的是OpenXml,可以搜了很久,只有一个ExcelPackage,用了之后发现缺胳膊少腿的,还有性能问题,所以还是只能换成老老实实的Interop的方式。但数据量比较大,怎么解决呢?

搜索了一下,使用Range的方式,先把数据保存在Object数组中,之后根据设定的大小一次性写入,速度的确提升很多

代码
private static void RangeWriteToSheet(FileInfo excelFile,string sheetName, System.Data.DataTable dtResult)
        {
            
object missing = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Excel.ApplicationClass appc 
= new Microsoft.Office.Interop.Excel.ApplicationClass();//lauch excel application
            Microsoft.Office.Interop.Excel.Range rangedata;
            Microsoft.Office.Interop.Excel.Workbook workbookData;
            Microsoft.Office.Interop.Excel.Worksheet worksheetData;

            
try
            {
                workbookData 
= appc.Application.Workbooks.Open(excelFile.FullName, missing, false, missing, missing, missing, missing, missing, missing, true, missing, missing, missing, missing, missing);
                
int sheetId = 0;
                
for (int k = 1; k <= workbookData.Worksheets.Count; k++)
                {
                    worksheetData 
= (Microsoft.Office.Interop.Excel.Worksheet)workbookData.Worksheets.get_Item(k);
                    
if (worksheetData.Name.Equals(sheetName))
                    {
                        sheetId 
= k;
                    }
                }

                worksheetData 
= (Microsoft.Office.Interop.Excel.Worksheet)workbookData.Worksheets.get_Item(sheetId);
                worksheetData.get_Range(
"A1""H1").AutoFilter(1, missing, Excel.XlAutoFilterOperator.xlAnd, missing, true);
              
                
                rangedata 
= worksheetData.get_Range("A2", missing);
                Microsoft.Office.Interop.Excel.Range xlRang 
= null;
                
int iEachSize = 2000;
                
int iParstedRow = 0, iCurrSize = 0;
                
int iColumnAccount = dtResult.Columns.Count;
                
int iRowCount = dtResult.Rows.Count;
                
object[,] objVal = new object[iEachSize, iColumnAccount];
                iCurrSize 
= iEachSize;
                
while (iParstedRow < iRowCount)
                {
                    
if ((iRowCount - iParstedRow) < iEachSize)
                        iCurrSize 
= iRowCount - iParstedRow;
                    
for (int i = 0; i < iCurrSize; i++)
                    {
                        
for (int j = 0; j < iColumnAccount; j++)
                            objVal[i, j] 
= dtResult.Rows[i + iParstedRow][j].ToString();
                    }
                    xlRang 
= worksheetData.get_Range("A" + ((int)(iParstedRow + 2)).ToString(), ((char)('A' + iColumnAccount - 1)).ToString() + ((int)(iParstedRow + iCurrSize + 1)).ToString());
                    xlRang.Value2 
= objVal;
                    iParstedRow 
= iParstedRow + iCurrSize;
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRang);
                workbookData.Save();
                workbookData.Close(Type.Missing, Type.Missing, Type.Missing);
            }
            
catch (Exception)
            {
                
throw;
            }
            
finally
            {
                appc.Quit();
                appc 
= null;

            }
        }


 

posted @ 2009-12-20 20:00 潘安+宋玉 阅读(117) 评论(0) 编辑
  2009年11月30日

因为实现的功能是读取excel2007第一个sheet的内容,经过一系列处理后,将结果写到第二个sheet中,这样现在很多的工具myxls,npoi用来就不好用了,所以只有在网上搜了很久

发现了codeplex上的一个项目:ExcelPackage(http://excelpackage.codeplex.com/)

这个类库中提供了一些基本的excel操作方法,直接操作xml的方式

速度还是不错的,但发布的版本中还存在很多的bug,大家用的时候最好先把Discussions看一下

主要是一个单引号的问题需要修改一下源代码

 

 

 

posted @ 2009-11-30 11:40 潘安+宋玉 阅读(295) 评论(0) 编辑
  2009年11月12日

百度搜索引擎提供了一段嵌入到页面中的代码

<form action="http://www.baidu.com/baidu" target="_blank">
<table><tr><td>
<input name=tn type=hidden value=baidu>
<input type=text name=word size=80>
<input type=hidden name=ie value="UTF-8">
<input type="submit" style="background:url(images/searchicon.gif) no-repeat; border:0; width:76px; height:26px; cursor:pointer" value="搜索">
</td></tr></table>
</form>

 

但在使用中由于我的页面时UTF-8的

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

 

所以我必须在百度给出的代码中加上这句

<input type=hidden name=ie value="UTF-8">

 

这个是第一部分,第二部分,我需要配置搜索条下的热门词汇,点击后直接进入搜索结果,代码如下

HtmlTableCell searchText = new HtmlTableCell();
                searchText.InnerHtml = string.Format("<a href=\"http://www.baidu.com/baidu?tn=baidu&word={0}&ie=UTF-8\" target=\"_blank\">{0}</a>|", dt.Rows[i]["SearchText"].ToString());
                
                tr_search.Cells.Add(searchText);
posted @ 2009-11-12 11:14 潘安+宋玉 阅读(269) 评论(2) 编辑
  2009年10月22日

通过创建新一个存储过程,在内部循环检查job的状态,当发现其执行成功之后,返回0。

Code

 

 

 

 

posted @ 2009-10-22 13:38 潘安+宋玉 阅读(182) 评论(0) 编辑
  2009年9月26日
摘要: [代码]阅读全文
posted @ 2009-09-26 13:52 潘安+宋玉 阅读(188) 评论(0) 编辑
摘要: 1.向程序传递参数[代码]通过在此处直接复制,可以实现类似可选参数的功能。这里提到了类似,就是这个参数我们还是一定要有的。加入我们希望让¥hostname是可选参数,即可以为空,此时就无法实现,运行时会提示没有参数,此功能在powershell2中有相应的方法可以解决2.测试目录或者文件是否存在[代码]此处主要是-pathtype这个参数,leaf表示文件,containor表示目录阅读全文
posted @ 2009-09-26 13:27 潘安+宋玉 阅读(107) 评论(0) 编辑
摘要: 最近刚刚换了工作,从做asp.net的网页开发,到了做微软Vendors 的SDET发现这个跨度还是挺打的,开始写一些脚本和C# Console工具这边文章主要讲怎样修改网卡的参数,手动修改可以通过点击“网卡”--“属性”--网卡的“配置”--“高级”对应到程序中,这些参数就对应到相应的注册表项[代码]...阅读全文
posted @ 2009-09-26 13:13 潘安+宋玉 阅读(121) 评论(0) 编辑
  2009年2月11日
摘要: 接着昨天的,先讲讲Entity framework创建实体之后,在代码中这么写DbMVCEntities context = new DbMVCEntities();nt count = (from e in context.Usrwhere e.username == usernamewhere e.password == passwordselect e).Count();接着通过count来...阅读全文
posted @ 2009-02-11 21:54 潘安+宋玉 阅读(569) 评论(1) 编辑
  2009年2月10日
摘要: 使用MVC模仿模板文件做了一个用户的登录,注册,修改密码的功能Controllerusing System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Web.Mvc.Ajax;using MvcTest.Models;namespace ...阅读全文
posted @ 2009-02-10 22:21 潘安+宋玉 阅读(713) 评论(0) 编辑