-4
嘿我有一個CSVHelper的問題。C#CsvHelper CsvHelper.Excel ClosedXML,給我的基本代碼的語法錯誤
我需要讀取一個相當不錯的Excel文件。但不幸的是,標題行不在第1行,它在第4行。我已經遇到了這個問題,並且始終以相同的方式處理它,在將它傳遞給CsvReader
之前,在ExcelParser
上調用.Read()
。但是,今天的事情是不同的,當我運行這段代碼,ClosedXML
讓我在reader.GetRecords<T>().ToList()
錯誤語法錯誤:
using CsvHelper.Excel;
using CsvHelper;
var excelParser = new ExcelParser(FilePath);
int header = 2;
for (int i = 0; i < header; i++)
{
excelParser.Read();
}
using (var reader = new CsvReader(excelParser))
{
reader.Configuration.Delimiter = ";";
reader.Configuration.RegisterClassMap<MaterialTemplateClassMap>();
var records = reader.GetRecords<TemplatesSheet>().ToList();
}
的類映射是很基本的Excel文件都不復雜。所以我沒有看到那裏的問題。也許我錯過了一些東西。 在從ClosedXML,消息運行時: 「語法錯誤」,ExceptionType:System.Exception的
at ClosedXML.Excel.CalcEngine.CalcEngine.GetParameters()
at ClosedXML.Excel.CalcEngine.CalcEngine.ParseAtom()
at ClosedXML.Excel.CalcEngine.CalcEngine.ParseUnary()
at ClosedXML.Excel.CalcEngine.CalcEngine.ParsePower()
at ClosedXML.Excel.CalcEngine.CalcEngine.ParseMulDiv()
at ClosedXML.Excel.CalcEngine.CalcEngine.ParseAddSub()
at ClosedXML.Excel.CalcEngine.CalcEngine.ParseCompare()
at ClosedXML.Excel.CalcEngine.CalcEngine.Parse(String expression)
at ClosedXML.Excel.CalcEngine.ExpressionCache.get_Item(String expression)
at ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression)
at ClosedXML.Excel.XLCell.get_Value()
at CsvHelper.Excel.ExcelParser.<Read>b__2(IXLCell cell) in c:\Users\chris.rodgers\Documents\GitHub\CsvHelper.Excel\src\CsvHelper.Excel\ExcelParser.cs:Row 130.
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at CsvHelper.Excel.ExcelParser.Read() in c:\Users\chris.rodgers\Documents\GitHub\CsvHelper.Excel\src\CsvHelper.Excel\ExcelParser.cs:Row 129.
at CsvHelper.CsvReader.Read()
at CsvHelper.CsvReader.<GetRecords>d__65`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at **Name removed**.Winform.Loader.ReadSchemeData.Read() in **Path removed**ReadSchemeData.cs:Row 45.
at **Name removed**.Winform.Converter.buttonAdditional_Click(Object sender, EventArgs e) in **Path removed**Converter.cs:Row 113.
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at **Name removed**.Program.Main() in **Path removed**\Program.cs:Row 23.
語法錯誤?什麼是確切的錯誤信息?你在編譯或運行時得到這個嗎?請更完整地回答你的問題。 – DavidG
如果您收到異常,發佈其詳細信息和堆棧跟蹤以及重現問題的代碼通常是一個好主意。請閱讀[mcve] –
缺少異常類型和消息......另外,我在「Excel根本不復雜」中直接哼了一聲 –