System.Reflection.Missing.Value的应用

本文介绍如何在C#中通过指定COM中的可选参数来操作Excel,并提供了一个具体的示例代码,展示了如何打开一个Excel文件并处理可能出现的文化设置问题。

在C#中,您可以用以下方法来指定COM中的可选参数
using System.Reflection; 
. . . 
. . . 
//System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); 
Excel.Application excel = new Excel.Application(); 
Excel.Workbook ewb = excel.Workbooks.Open(@"f:\sample.xls",Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value); 

另外,目前在非en-US culture下,在.NET中使用Excel还存在一些问题,所以,如果您遇到了问题,可以如上加入System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");一句来事先改变一下culture. 

关于在C#.NET中使用Excel的更详细的示例代码,您可以参考以下一些文档: 
HOWTO: Automate Microsoft Excel from Visual C# .NET   
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q302084 

HOWTO: Fill/Retrieve Excel Data Using Arrays With C# .NET 
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q302084 

HOW TO: Handle Events for Excel by Using Visual C# .NET   
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q302815   

 

转自:http://hi.baidu.com/limeng_hoho/item/479dd9776821d25a0c0a076a

此段代码报错CS1061“ContentControl"未包含”checkedSymbol“的定义,并且找不到可接受第一个”ContentControl“类型参数的可访问扩展方法”CheckedSymbol“(是否缺少using指令或程序集引用)请帮忙修改并给出修改后的代码using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Office.Interop.Word; using System.Windows.Forms; using System.IO; using System.Xml.Linq; using Word = Microsoft.Office.Interop.Word; using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button; using System.Security.Cryptography; using System.Drawing; namespace Export { class MyAPQP { public static void WdExport() { //新增一个word文档 object noThing = System.Reflection.Missing.Value; Document wdDoc = MyWord.WdApplication.Documents.Add(Template: ref noThing, NewTemplate: ref noThing, DocumentType: ref noThing, Visible: ref noThing); #region 页面及样式设置 MyWord.SetPageSetup(document: wdDoc); //页面设置 MyWord.SetStyle(document: wdDoc, styleType: WdBuiltinStyle.wdStyleNormal, fontSize: 9.0f, paragraphAlignment: WdParagraphAlignment.wdAlignParagraphLeft); //正文样式(WdBuiltinStyle.wdStyleNormal)设置 小五 MyWord.SetStyle(document: wdDoc, styleType: WdBuiltinStyle.wdStyleHeader, fontSize: 9.0f, paragraphAlignment: WdParagraphAlignment.wdAlignParagraphCenter); //页眉样式(WdBuiltinStyle.wdStyleHeader)设置 小五 MyWord.SetStyle(document: wdDoc, styleType: WdBuiltinStyle.wdStyleFooter, fontSize: 9.0f, paragraphAlignment: WdParagraphAlignment.wdAlignParagraphCenter); //页脚样式(WdBuiltinStyle.wdStyleFooter)设置 小五 MyWord.SetStyle(document: wdDoc, styleType: WdBuiltinStyle.wdStyleTitle, fontSize: 14.0f, paragraphAlignment: WdParagraphAlignment.wdAlignParagraphCenter, spaceBefore: 4.0f, spaceAfter: 4.0f); //标题样式(WdBuiltinStyle.wdStyleTitle)设置 四号 MyWord.SetStyle(document: wdDoc, styleType: WdBuiltinStyle.wdStyleHeading1, fontSize: 12.0f, paragraphAlignment: WdParagraphAlignment.wdAlignParagraphL
03-13
exception was thrown while activating Castle.Proxies.AirCityAPPAttendanceServiceProxy -> Castle.Proxies.EquipmentAnalysisServiceProxy -> AirCity.Services.Asset.Application.Device.DeviceManagementAppService -> AirCity.Services.Asset.Application.Device.InventoryRecordAppService.] [ operacityproduct] [e0127d8f52964b0b978a8b770a5f208c] Autofac.Core.DependencyResolutionException: An exception was thrown while activating Castle.Proxies.AirCityAPPAttendanceServiceProxy -> Castle.Proxies.EquipmentAnalysisServiceProxy -> AirCity.Services.Asset.Application.Device.DeviceManagementAppService -> AirCity.Services.Asset.Application.Device.InventoryRecordAppService. ---------- Exception Data ---------- ActivatorChain = Castle.Proxies.AirCityAPPAttendanceServiceProxy -> Castle.Proxies.EquipmentAnalysisServiceProxy -> AirCity.Services.Asset.Application.Device.DeviceManagementAppService -> AirCity.Services.Asset.Application.Device.InventoryRecordAppService ---> Autofac.Core.DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'AirCity.Services.Asset.Application.Device.InventoryRecordAppService' can be invoked with the available services and parameters: 2025-11-21 11:52:02.680 +08:00Cannot resolve parameter 'Volo.Abp.Domain.Repositories.IRepository`2[Suncere.AirCityProduct.Models.InventoryRecord,System.Int32] inventoryRecordRepository' of constructor 'Void .ctor(Volo.Abp.Domain.Repositories.IRepository`2[Suncere.AirCityProduct.Models.InventoryRecord,System.Int32], Microsoft.Extensions.Logging.ILogger`1[AirCity.Services.Asset.Application.Device.InventoryRecordAppService], Volo.Abp.Domain.Repositories.IRepository`1[Suncere.AirCityProduct.Models.BSDDevice])'. [ at Autofac.Core.Activators.Reflection.ReflectionActivator.GetValidConstructorBindings(ConstructorInfo[] availableConstructors, IComponentContext context, IEnumerable`1 parameters) INF at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) at Autofac.Core.Resolving.InstanceLookup.CreateInstance(IEnumerable`1 parameters) ] [ --- End of inner exception stack trace --- operacityproduct at Autofac.Core.Resolving.InstanceLookup.CreateInstance(IEnumerable`1 parameters) ] [ at Autofac.Core.Resolving.InstanceLookup.Execute() e0127d8f52964b0b978a8b770a5f208c at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request) at Autofac.Core.Resolving.ResolveOperation.Execute(ResolveRequest request) ] at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance) Executing ObjectResult, writing value of type ' at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters) Suncere.Abp.Application.Contracts.Dtos.RemoteServiceResponseDto`1[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] at Microsoft.AspNetCore.Mvc.Controllers.ServiceBasedControllerActivator.Create(ControllerContext actionContext) '. at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() --- End of stack trace from previous location where exception was thrown --- 2025-11-21 11:52:02.686 +08:00 at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) [[INF11:52:02 ] [operacityproductERR] [] e0127d8f52964b0b978a8b770a5f208c---------- Exception Data ---------- ActivatorChain = Castle.Proxies.AirCityAPPAttendanceServiceProxy -> Castle.Proxies.EquipmentAnalysisServiceProxy -> AirCity.Services.Asset.Application.Device.DeviceManagementAppService -> AirCity.Services.Asset.Application.Device.InventoryRecordAppService ] Executed action [AirCity.Services.OperaBase.Application.KaoQin.AirCityAPPAttendanceService.GetAttendanceManagement (AirOpera.Services.OperaBase.Application)11:52:02 in 29.8185INFms] Executing ObjectResult, writing value of type '2025-11-21 11:52:02.689 +08:00Suncere.Abp.Application.Contracts.Dtos.RemoteServiceResponseDto`1[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] [DBG'. ] [[11:52:02operacityproduct ] [INFe0127d8f52964b0b978a8b770a5f208c] ] HandleAfterActionEvent: Missing span contextExecuted action 2025-11-21 11:52:02.690 +08:00AirCity.Services.OperaBase.Application.KaoQin.AirCityAPPAttendanceService.GetAttendanceManagement (AirOpera.Services.OperaBase.Application) [INF in ] [29.8185operacityproductms] [ [11:52:02e0127d8f52964b0b978a8b770a5f208c DBG] ] HandleAfterActionEvent: Missing span contextExecuted endpoint ' AirCity.Services.OperaBase.Application.KaoQin.AirCityAPPAttendanceService.GetAttendanceManagement (AirOpera.Services.OperaBase.Application)' [2025-11-21 11:52:02.692 +08:0011:52:02 [ INFINF] ] [Executed endpoint 'operacityproduct] [AirCity.Services.OperaBase.Application.KaoQin.AirCityAPPAttendanceService.GetAttendanceManagement (AirOpera.Services.OperaBase.Application)'] Request finished in 44.1754ms 500 application/json; charset=utf-8 [11:52:02 INF] Request finished in 44.1754ms 500 application/json; charset=utf-8 2025-11-21 11:52:02.694 +08:00 [DBG] [operacityproduct] [] HandleStartEvent: Ignoring path: /api/v2/spans [11:52:02 DBG] HandleStartEvent: Ignoring path: /api/v2/spans 2025-11-21 11:52:04.335 +08:00 [DBG] [operacityproduct] [] HandleStartEvent: Ignoring path: /api/v2/spans [11:52:04 DBG] HandleStartEvent: Ignoring path: /api/v2/spans 2025-11-21 11:52:05.242 +08:00 [DBG] [operacityproduct] [] HandleExceptionEvent: Missing span context [11:52:052025-11-21 11:52:05.244 +08:00 [ DBGDBG] [] operacityproduct] [HandleExceptionEvent: Missing span context ] HandleStopEvent: Missing span context [11:52:05 DBG] HandleStopEvent: Missing span context 2025-11-21 11:52:05.256 +08:00 [DBG] [operacityproduct] [] HandleExceptionEvent: Missing span context [2025-11-21 11:52:05.257 +08:0011:52:05 [DBG ] [DBGoperacityproduct] [] ] HandleExceptionEvent: Missing span context HandleStopEvent: Missing span context [11:52:05 DBG] HandleStopEvent: Missing span context
最新发布
11-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值