Tag: ms office

用powershell查找最后保存的word和excel文件

我有一个文件夹与子文件夹,我想要运行一个PowerShell脚本,find所有的办公文件(单词和Excel 2003,2007和2010年),并打印“最后保存”属性,我们可以find属性,文件的详细信息选项卡。 任何人都可以帮忙吗? —解决scheme— $word = New-Object -Com Word.Application $word.Visible = $false #to prevent the document you open to show $doc = $word.Documents.Open($path) $binding = "System.Reflection.BindingFlags" -as [type] Foreach($property in $doc.BuiltInDocumentProperties) { try { $pn = [System.__ComObject].invokemember("name",$binding::GetProperty,$null,$property,$null) if ($pn -eq "Last author") { $lastSaved = [System.__ComObject].invokemember("value",$binding::GetProperty,$null,$property,$null) write-host "Last saved by: "$lastSaved } } catch { […]

在office.js中为excel设置条件格式

我需要一种方法来在office.js加载项中设置条件格式。 目前我认为我可以使用VBA来根据插件设置的单元值来设置它,但是直接从office.js中直接执行这个操作是非常好的。 我正在寻找一些创造性的解决方法,直到Microsoft在加载项中本地执行此操作。

读取/写入Excel 2007密码保护的文档

Office 2007使用什么方法进行encryption(从Office菜单中selectencryption并设置密码时)? 我的C#应用​​程序需要创build并读取encryption的Excel 2007文件(.xlsx)。 这些文件保持从Excel访问是很重要的,所以我必须使用微软的encryption方法,不能自己酿造。 正常的Excel 2007文件是一个ZIP压缩文件,我正在使用ExcelPackage访问它,它在内部使用* System.Io.Packaging.Package *(.net 3.0的一部分)。 但是,Office中的encryption不是标准的ZIPencryption。 包类似乎不支持encryption,并报告损坏的文件。 7Zip打开文件(没有提供密码),并显示一些二进制文件里面。

与Microsoft.Office.Interopunit testing在生成服务器上失败

我写了一个unit testing。 被testing的代码引用了Microsoft.Office.Interop.Excel.dll。 testing在我的机器上运行良好,但在构build服务器上失败。 它在Excel应用程序实例化的行上失败: var application = new Application { Visible = Visible }; 错误是: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered 这是否意味着我必须在我的构build服务器上安装可再分发的主互操作程序集? 如果是这样,我是否也需要在生成服务器上安装Excel? 编辑: Microsoft.Office.Interop.Excel.dll是包含在我的解决scheme,它是从那里引用。

使用Linq创buildOffice Excel文档到XML,XMLNS,XDeclaration,单元格格式(工作)

我需要在C#和Linq中将这个XML复制到XML中。 我不希望任何其他图书馆的正常.NET的依赖。 XML如下所示。 问题:我不知道如何打印这两行: <?mso-application progid="Excel.Sheet"?> <Data ss:Type="String">name</Data> 完整的XML文档: <?xml version="1.0" encoding="utf-8" ?> <?mso-application progid="Excel.Sheet"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"> <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office"></OfficeDocumentSettings> <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"></ExcelWorkbook> <Worksheet ss:Name="Sheet 1"> <Table> <Row> <Cell> <Data ss:Type="String">name</Data> </Cell> <Cell> <Data ss:Type="String">status</Data> </Cell> </Row> <Row> <Cell> <Data ss:Type="String">Niike2</Data> </Cell> <Cell> <Data ss:Type="String">Enabled</Data> </Cell> </Row> </Table> </Worksheet> </Workbook> […]

从Excel中读取数据SpreadSheet – 无法对空引用执行运行时绑定

我有下面的代码来读取Excel文件中的数据,我遇到的问题是,当我尝试读取范围数据,我得到一个exception“不能执行空引用上的运行时绑定”在这一行 if (Int32.TryParse(xlRange.Cells[1, 4].Value2.ToString(), out value)) 我想知道的是如何正确访问范围内的信息。 提前致谢 void ReadFromExcelToGrid2(String fileNameString) { try { Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(fileNameString); //get list of worksheets associated with the current workbook Microsoft.Office.Interop.Excel.Sheets worksheets = xlWorkbook.Worksheets; //list the work books in a dropdownlist IDictionary<int, String> sheets = new Dictionary<int, String>(); foreach (Microsoft.Office.Interop.Excel.Worksheet displayWorksheet in xlWorkbook.Worksheets) […]

OpenXml和无法创build互斥

我试图通过openXml库创buildExcel文档,但是当我想从大量的数据创buildExcel,服务器鞋我无法创build互斥体。 (从HRESULTexception:0x80131464)错误,堆栈跟踪是: [IsolatedStorageException: Unable to create mutex. (Exception from HRESULT: 0x80131464)] System.IO.IsolatedStorage.IsolatedStorageFile.Open(String infoFile, String syncName) +0 System.IO.IsolatedStorage.IsolatedStorageFile.Lock(Boolean& locked) +370 System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf) +468 System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, IsolatedStorageFile isf) +35 MS.Internal.IO.Packaging.SafeIsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, ReliableIsolatedStorageFileFolder folder) +102 MS.Internal.IO.Packaging.PackagingUtilities.CreateUserScopedIsolatedStorageFileStreamWithRandomName(Int32 […]

在查询Excel 2010时诊断OLEDBexception

要通过SQL查询Excel表格,我曾经使用过: Dim excelConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strPath + ";Extended Properties=""Excel 8.0;IMEX=1;HDR=YES;""" 要么 Dim excelConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + strPath + ";Extended Properties=""Excel 12.0;IMEX=1;HDR=YES;""" 现在这个工作正常,直到我安装Office 2010。 现在我得到一个 Microsoft.Ace.OLEDB.12.0提供程序未在此计算机上注册exception。 我怎样才能find正确的连接string/提供者?

在Excel中查询Excel表格

我想用c#读取Excel文件,使用下面的代码 string excelFileName = "Book2.xls"; string excelConnectString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Book2.xls;Extended Properties=""Excel 8.0;HDR=YES;"""; //string excelConnectString = @"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " + excelFileName + ";" + "Extended Properties = Excel 8.0; HDR=Yes;IMEX=1"; OleDbConnection objConn = new OleDbConnection(excelConnectString); OleDbCommand objCmd = new OleDbCommand("Select * From [Sheet1$]", objConn); OleDbDataAdapter objDatAdap = new OleDbDataAdapter(); objDatAdap.SelectCommand = objCmd; […]

用C#编写MS Office – 有可能吗?

像Excel这样的MS office应用程序可以使用Visual Basic for Applications进行编程。是否可以使用C#编写MS Office以执行高级任务?