2013-07-10 25 views
0

我正在使用SyncFusion XlsIo將數據導出到Excel表單。將數據導出爲ex​​cel時遇到一些問題。我認爲我在excel模板中遇到問題。所以首先我想知道如何爲excel創建模板,以便我可以將值放在那裏?我想要做類似的事情,這是由SyncFusion SDK提供的示例應用程序。我試圖複製該excel模板,但它不起作用,並拋出異常。異常詳情如下。ArgumentOutOfRangeException在Excel模板中使用XlsIO時

異常信息:System.ArgumentOutOfRangeException了未處理由用戶 代碼的HResult = -2146233086消息=找不到屬性參數 名稱:strText的來源= Syncfusion.XlsIO.WinRT PARAMNAME = strText的
堆棧跟蹤: 在Syncfusion .XlsIO.Implementation.TemplateMarkers.TemplateMarkersImpl.GetNextValue(對象 值,字符串& strText中,字符串& newNumberFormat,

類型& NEWTYPE) 在Syncfusion.Xls IO.Implementation.TemplateMarkers.TemplateMarkersImpl.SetSimpleValue(對象 值,字符串strText中,IWorksheet片,

IMigrantRange migrantRange,IList`1 arrMarkerCells,IList的 lstArguments,MarkerOptionsImpl選項,RangeBuilder助洗劑, UnknownVariableAction

動作,串NUMBERFORMAT,類型VALUETYPE) 在Syncfusion.XlsIO.Implementation.TemplateMarkers.TemplateMarkersImpl.SetArrayValue(IList的 值,字符串strText中,IWorksheet片,

IMigrantRange migrantRange,IList`1 arrMarkerCells,IList的 lstArguments,MarkerOptionsImpl選項,RangeBuilder助洗劑, UnknownVariableAction

動作,VariableTypeAction variableTypeAction) 在Syncfusion.XlsIO.Implementation.TemplateMarkers.TemplateMarkersImpl.SetUnknownVariable(對象 值,字符串strText中,IWorksheet片,

IMigrantRange migrantRange,IList`1 arrMarkerCells,IList的 lstArguments,MarkerOptionsImpl選項,RangeBuilder建設者, UnknownVariableAction

ACTI上,VariableTypeAction variableTypeAction) 在Syncfusion.XlsIO.Implementation.TemplateMarkers.TemplateMarkersImpl.SetVariable(字符串 strVariable,字符串strText中,IWorksheet片,

IMigrantRange migrantRange,IList`1 arrMarkerCells,IList的 lstArguments,MarkerOptionsImpl選項,RangeBuilder助洗劑, UnknownVariableAction

動作) 在Syncfusion.XlsIO.Implementation.TemplateMarkers.TemplateMarkersImpl.ApplyMarker(IWorksheet 片,IList`1 arrCells,我的Int32,IMigrantRange

migrantRange,UnknownVariableAction action) at Syncfusion.XlsIO.Implementation.TemplateMarkers.TemplateMarkersImpl。ApplyMarkers(IWorksheet 片,List`1 arrLabels,UnknownVariableAction

動作) 在Syncfusion.XlsIO.Implementation.TemplateMarkers.TemplateMarkersImpl.ApplyMarkers(IWorkbook 書,UnknownVariableAction動作) 在Syncfusion.XlsIO.Implementation.TemplateMarkers.TemplateMarkersImpl .ApplyMarkers(UnknownVariableAction 動作) 在InvoiceExportDemo.ExportToExcel.d__0.MoveNext()在 d:\項目\ InvoiceExportDemo \ InvoiceExportDemo \助手類

\ ExportToExcel.cs:線29

行:marker.ApplyMarkers(UnknownVariableAction.Skip);

回答

0

此異常是由於使用問題提出。輸入模板中的自定義類屬性名稱和標記應匹配。使用以下步驟創建帶有標記的輸入模板並參考提供的示例。

語法::

與模板標記創建輸入模板 %classname.PropertyName

實施例: %InvoiceItem.ItemName

表示在Excel中上面的字符串然後在示例中使用下面的代碼片段。

List<InvoiceItem> items = new List<InvoiceItem>(); 
items.Add(new InvoiceItem("Essential Studio WinRT", 1, 399, 50)); 
items.Add(new InvoiceItem("Essential ASP.NET ", 1, 995, 70)); 
//Create Template Marker Processor 
ITemplateMarkersProcessor marker = book.CreateTemplateMarkersProcessor(); 
//Binding the business object with the marker. 
marker.AddVariable("InvoiceItem", items); 

//Applies the marker. 
marker.ApplyMarkers(UnknownVariableAction.Skip); 

樣品:Template_Marker_Sample.zip

問候,

約翰遜

相關問題