ImageVerifierCode 换一换
格式:DOCX , 页数:9 ,大小:26.85KB ,
资源ID:3333465      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3333465.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(批量编辑Excel x64.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

批量编辑Excel x64.docx

1、批量编辑Excel x64批量编辑Excel 2010 x64首先添加引用:using Microsoft.Office.Interop.Excel;using System.Drawing;using System.IO;代码usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingMicrosoft.Office.Interop.Excel;usingSystem.Drawing;usingSystem.IO;namespaceExcelHelp/Date:2010.03.31/Au

2、thor:Mr.Brooks/HomePage:/Email:undead_47/classExcelHelp/将一个工作簿中一个工作表中的内容复制到另一个工作簿的一个工作表中/源工作薄的完整路径/源工作表名/目标工作薄的完整路径/目的工作表名privatestaticvoidfnCopy(stringv_strSourceWorkbook,stringv_strSourceWorksheet,stringv_strDestWorkbook,stringv_strDestWorksheet)Applicationapp=newApplication();Workbooksrcbook=app.

3、Workbooks.Open(v_strSourceWorkbook);Worksheetsrcsheet=srcbook.Worksheetsv_strSourceWorksheet;Workbookdestbook=app.Workbooks.Open(v_strDestWorkbook);Worksheetdestsheet=destbook.Worksheetsv_strDestWorksheet;try/Worksheet.UsedRange:获取工作表中所使用的范围for(inti=1;i=srcsheet.UsedRange.Rows.Count;i+)for(intj=1;j=

4、srcsheet.UsedRange.Columns.Count;j+)/将Excel的颜色与RGB联系起来if(srcsheet.Cellsi,j.Interior.Color!=ColorTranslator.ToOle(Color.FromArgb(255,204,153)destsheet.Cellsi,j.Value2=srcsheet.Cellsi,j.Value2;/屏蔽Excel的提示信息app.Application.DisplayAlerts=false;destbook.Save();catch(Exceptionex)throwex;finallyapp.Quit();

5、System.Runtime.InteropServices.Marshal.ReleaseComObject(app);System.Runtime.InteropServices.Marshal.ReleaseComObject(srcbook);System.Runtime.InteropServices.Marshal.ReleaseComObject(srcsheet);System.Runtime.InteropServices.Marshal.ReleaseComObject(destbook);System.Runtime.InteropServices.Marshal.Rel

6、easeComObject(destsheet);app=null;srcbook=null;destbook=null;srcsheet=null;destsheet=null;GC.Collect();Range.Interior.Color是Office中表示颜色的方法,其返回一个整数,表示一种特定的颜色:但是我们平时用的最多的是RGB表示的颜色,可以用srcsheet.Cellsi,j.Interior.Color!=ColorTranslator.ToOle(Color.FromArgb(255,204,153)将ColorIndex与RGB进行关联。代码/判断一个工作簿的一个工作表

7、有没有添加保护/工作簿的完整路径/工作表名privatestaticvoidfn判断工作表是否被保护(stringv_strDir,stringv_strSheetName)StringBuildersb=newStringBuilder();Applicationapp=newApplication();DirectoryInfodir=newDirectoryInfo(v_strDir);try/递归查找所有Excel2007/2010的文件foreach(FileInfofindir.GetFiles(*.xlsx,SearchOption.AllDirectories)Workbook

8、book=app.Workbooks.Open(f.FullName);if(book.Worksheetsv_strSheetName.ProtectContents)sb.Append(book.Name+,);app.Application.DisplayAlerts=false;book.Save();catch(Exceptionex)throwex;finallyapp.Quit();System.Runtime.InteropServices.Marshal.ReleaseComObject(app);app=null;GC.Collect();Console.WriteLine

9、(sb.ToString();若不知道Excel工作簿或工作表的密码,可以用Passware进行破解,经过测试,Passware 可以破解Office 2003/2007/2010,其官方主页称可以破解Windows 7 的 BitLocker 加密技术。代码/判断一个工作表中所有的单元格是否包含公式/工作簿的完整路径privatestaticvoidfn判断单元格是否包含公式(stringv_strPath)StringBuildersb=newStringBuilder();Applicationapp=newApplication();DirectoryInfodir=newDirect

10、oryInfo(v_strPath);tryforeach(FileInfofileindir.GetFiles(*.xlsx,SearchOption.AllDirectories)Workbookbook=app.Workbooks.Open(file.FullName);foreach(Worksheetsheetinbook.Worksheets)for(inti=1;isheet.UsedRange.Rows.Count;i+)for(intj=1;jsheet.UsedRange.Columns.Count;j+)if(sheet.Cellsi,j.Interior.Color!=

11、ColorTranslator.ToOle(Color.FromArgb(255,204,153)if(sheet.Cellsi,j.HasFormula)sb.Append(book.Name+sheet.Name+第+i.ToString()+行第+j.ToString()+列包含公式!n);catch(Exceptionex)throwex;finallyapp.Quit();System.Runtime.InteropServices.Marshal.ReleaseComObject(app);app=null;GC.Collect();Console.WriteLine(sb.ToS

12、tring();代码/获取指定工作簿的所有工作表/工作簿的完整路径privatestaticvoidfn获取指定工作簿的所有工作表(stringv_strDir)StringBuildersb=newStringBuilder();Applicationapp=newApplication();DirectoryInfodir=newDirectoryInfo(v_strDir);tryforeach(FileInfofindir.GetFiles(*.xlsx,SearchOption.AllDirectories)Workbookbook=app.Workbooks.Open(f.Full

13、Name);sb.Append(book.Name);foreach(Worksheetsheetinbook.Worksheets)sb.Append(sheet.Name+);sb.Append(n);app.Application.DisplayAlerts=false;book.Save();catch(Exceptionex)throwex;finallyapp.Quit();System.Runtime.InteropServices.Marshal.ReleaseComObject(app);app=null;GC.Collect();Console.WriteLine(sb.T

14、oString();批量转换Excel的格式代码/批量转换Excel2003至Excel2007/2010格式/可以修改XlFileFormat枚举的值来转换为想要的格式/工作簿的查找路径privatestaticvoidfn批量转换Excel文件格式(stringv_strDir)Applicationapp=newApplication();DirectoryInfodir=newDirectoryInfo(v_strDir);Workbookbook;app.Application.DisplayAlerts=false;tryforeach(FileInfofiindir.GetFil

15、es(*.xls,SearchOption.AllDirectories)book=app.Workbooks.Open(fi.FullName);book.SaveAs(fi.DirectoryName+fi.Name.Replace(fi.Extension,string.Empty)+.xlsx,XlFileFormat.xlOpenXMLWorkbook);catch(Exceptionex)throwex;finallyapp.Quit();System.Runtime.InteropServices.Marshal.ReleaseComObject(app);app=null;GC

16、.Collect();比较两个工作表的内容代码/比较两个工作表的内容/第一个工作簿的路径/第二个工作簿的路径privatestaticvoidfn比较两个工作表的内容(stringv_strSourcePath,stringv_strDestPath)Applicationapp=newApplication();WorkbooksrcBook=app.Workbooks.Open(v_strSourcePath);WorkbookdestBook=app.Workbooks.Open(v_strDestPath);/记录查找结果到本文文件中FileStreamfs=newFileStream(log.txt,FileMode.OpenOrCreate,FileAccess.ReadWrite);StreamWritersw=newStreamWriter(fs);tryforeach(WorksheetsheetinsrcBook.Worksheets)for(inti=1;i=sheet.UsedRange.Rows.Count;i+)

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1