我有以下代码(简化以显示问题):
var wdApp = new Application();
var wdDoc = wdApp.Documents.Open("C:\foo.docx");
wdApp.StatusBar = "Updating...";
var rng = wdDoc.Range(10, 10);
if ((bool)rng.Information(WdInformation.wdWithInTable))
{
}
//StatusBar value is gone...
Run Code Online (Sandbox Code Playgroud)
编辑:
提供的代码使用NetOffice而不是Microsoft的interop库,因此语法是正确的.您可能会在提供的屏幕截图中注意到它们是从正在运行的应用程序中获取的.断点,突出显示当前执行的代码行,以及右侧单词应用程序中代码的实际结果.一开始就有所需的状态栏"Tabelle 8 von 17 wird neu erstellt." (17个表中的表8正在重新创建)并且在下一步我的状态栏已经消失,其默认内容为"165 von8227Wörtern"(8227个单词中的165个)
我正在使用NetOffice创建Word文档.
几乎没有文档,我很难添加标题.有人可以帮忙吗?
我正在使用C#framework 4.5,netoffice 1.6和sharpdevelop 4.4.1来操作位于网络共享中的excel工作簿,从Outlook中.
在某些时候,我需要更改工作簿对象(ewb)的文件访问权限,以便像这样读写:
ewb.ChangeFileAccess(Excel.Enums.XlFileAccess.xlReadWrite, System.Reflection.Missing.Value, true);
Run Code Online (Sandbox Code Playgroud)
在更改文件访问权限之前,我检查文件是否在服务器上被锁定.如果文件被锁定,我将通知用户稍后重试该操作.
现在,我想在通知中包含锁定excel文件的用户名.我搜索了msdn,netoffice论坛等等,但还没有找到解决方案.我知道,如果你打开excel文件readwrite,它会将用户的名字存储在xlsx文件中.如何通过c#访问该特定信息?
编辑:我最终这样做:
public string GetExcelFileOwner(string path, NetOffice.ExcelApi.Enums.XlFileFormat ffmt) {
string tempmark = "~$";
if(ffmt==NetOffice.ExcelApi.Enums.XlFileFormat.xlExcel8) {
tempmark = "";
}
string uspath = Path.Combine(Path.GetDirectoryName(path), tempmark + Path.GetFileName(path));
if (!File.Exists(uspath)) return "";
var sharing = FileShare.ReadWrite | FileShare.Delete;
using (var fs = new FileStream(uspath, FileMode.Open, FileAccess.Read, sharing))
using (var br = new BinaryReader(fs, Encoding.Default)) {
if(ffmt==NetOffice.ExcelApi.Enums.XlFileFormat.xlExcel8) {
byte[] ByteBuffer = new byte[500];
br.BaseStream.Seek(150, SeekOrigin.Begin);
br.Read(ByteBuffer, 0, 500);
return matchRegex(System.Text.Encoding.UTF8.GetString(ByteBuffer), @"(?=\w\w\w)([\w, ]+)").Trim();
}
else …Run Code Online (Sandbox Code Playgroud) 我已经在Micorsoft.Office.Interop.Wordasp.net 中找到并替换了解决方案,我想将此解决方案移至NetOffice没有 Microsoft Word 的 asp.net 服务器中。我收到错误
未找到 progid
。我做错了什么,因为在我有 Microsoft Word 的计算机上,此代码在 NetOffice 中工作正常?
Word.Application wordApp = new Word.Application();<-- 这是这个错误
我正在使用 NetOffice 库开发 Outlook 加载项。这是一次很好的体验,但最后我更换了驱动器,重新安装了 Windows、Office 等。现在我的加载项无法运行,在 Outlook 选项的“COM 加载项”中我看到:
Load Behavior: Not loaded. A runtime error occurred during the loading of the COM Add-in
这个问题甚至在 NetOffice 的简单示例中也存在,即该项目NetOffice Tools - Simple,它基本上不执行任何操作。
我将添加的构造函数放入日志记录代码(到文件)中,但它没有运行,因此即使构造函数也没有被命中。
有什么提示如何解决它吗?
编辑:使用 AddInSpy 我发现加载项状态为:
Add-in DLL path is not found.
但不知道如何继续处理此信息。
我正在使用NetOffice编辑Excel电子表格.如果我从Excel用户定义的函数调用代码,它将不允许我编辑调用电子表格.
Excel.Application excelApplication = Excel.Application.GetActiveInstance();
Excel.Worksheet workSheet = (Excel.Worksheet) excelApplication.ActiveSheet;
Excel.Range cell = workSheet.Cells[2, 2];
object value = cell.Value; //works
cell.Value = 3; //Throws Exception
Run Code Online (Sandbox Code Playgroud)
是否有一种解决方法可以让我这样做?
例外是
"System.Runtime.InteropServices.COMException(0x80004005):有关详细信息,请参阅内部异常.--- System.Reflection.TargetInvocationException:调用目标抛出了异常.---> System.Runtime. InteropServices.COMException:来自HRESULT的异常:0x800A03EC ---内部异常堆栈跟踪结束---在System.RuntimeType.InvokeDispMethod(String name,BindingFlags invokeAttr,Object target,Object [] args,Boolean [] byrefModifiers,Int32 culture, String. [namedParameters)在System.RuntimeType.InvokeMember(String name,BindingFlags bindingFlags,Binder binder,Object target,Object [] providedArgs,ParameterModifier [] modifiers,CultureInfo culture,String [] namedParams)at System.Type.InvokeMember(String在NetOffice.Invoker.PropertySet(COMObject comObject,String name,对象[] va lue)atExxtice.ExcelApi.Range.set_Value(Object value)at ExcelExamplesCS45.Example01.RunExample()in\psf\home\Documents\Visual Studio 2013\Projects\Excel-REPL\Excel-REPL\Example01.cs:第29行在\ psf\home\Documents\Visual Studio 2013\Projects\Excel-REPL\Excel-REPL\MainClass.cs中的ClojureExcel.MainClass.Test():第310行"