阅读文本格式从Excel中使用的Microsoft.Office.Interop.Excel [英] Reading text format from Excel using Microsoft.Office.Interop.Excel

查看:363
本文介绍了阅读文本格式从Excel中使用的Microsoft.Office.Interop.Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读的文本格式如通过

I am trying to read text format e.g. the Strikethough property via

myworksheet.Cells[row, col].DisplayFormat.Style.Font.Strikethrough;

然而,结果总是假的,不管实际的格式是什么。

However, the result is always false, not matter what the actual formatting is.

右键在这之前,我读同一小区内使用的值:

Right before that, I read the value of the same cell using:

myworksheet.Cells[row, col].Value;

和得到正确的值。

当我尝试使用调试器来读取 myworksheet.Cells [行,列] .DisplayFormat.Style.Font.Strikethrough 我收到错误的。

When I try using the debugger to read myworksheet.Cells[row, col].DisplayFormat.Style.Font.Strikethrough I receive false.

当我尝试使用调试器来读取格式的字体并查看其属性,我得到:

When I try using the debugger to read the format's Font and see its properties I get:

异常详细信息:

删除线{System.Reflection.TargetInvocationException:异常被抛出调用的目标。 ---> System.Runtime.InteropServices.COMException:旧格式或无效类型库。 (从HRESULT异常:0x80028018(TYPE_E_INVDATAREAD))    ---内部异常堆栈跟踪的结尾---    在System.RuntimeType.InvokeDispMethod(字符串名称,的BindingFlags invokeAttr,对象目标,对象[] ARGS,布尔[] byrefModifiers,的Int32文化的String [] namedParameters)    在System.RuntimeType.InvokeMember(字符串名称,的BindingFlags的BindingFlags,活页夹粘结剂,对象目标,对象[] providedArgs,ParameterModifier []调节剂,CultureInfo的文化的String [] namedParams)    在System.Dynamic.IDispatchComObject.GetMembers(IEnumerable`1名)} System.Reflection.TargetInvocationException

Strikethrough {System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD)) --- End of inner exception stack trace --- at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at System.Dynamic.IDispatchComObject.GetMembers(IEnumerable`1 names)} System.Reflection.TargetInvocationException

我的Office 2010的x86安装在Windows 7 SP1 x64操作系统,我从.NET 4.0的项目引用的Microsoft.Office.Interop.Excel版本14。

I have Office 2010 x86 installed on a Windows 7 SP1 x64 OS and I'm referencing Microsoft.Office.Interop.Excel version 14 from a .NET 4.0 project.

我创建了以编程方式使用相同的库的.xlsx文件,并通过Excel的用户界面手动添加的文本格式。

I created the .xlsx file programmatically using the same library and added the text formatting manually via Excel's UI.

抛出通过调试器(手表和即时)访问的异常暗示该库的版本可能会过时,但是,14版本似乎是正确的版本(http://www.microsoft.com/en-我们/下载/ details.aspx?ID = 3508)。

The exception thrown by the access via debugger (watch and immediate) hints that the library version may be out of date, however, version 14 seems to be the correct version (http://www.microsoft.com/en-us/download/details.aspx?id=3508).

我在想什么?

推荐答案

在VBA中你通常只需要调用单元(R,C).Font 直接,没有样式。

In VBA you'd typically just call Cells(r,c).Font directly, without the Style.

这篇关于阅读文本格式从Excel中使用的Microsoft.Office.Interop.Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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