Tag: 帮助

使用FileHelpers,如何从上传的Excel文件中提取logging

FileHelpers的一个捆绑示例显示了如何从/向Microsoft Excel工作表中提取和插入logging,如下所示: 使用与inputExcel文件中的列对应的成员定义一个类 [DelimitedRecord("|")] public class CustomersVerticalBar { public string CustomerID; public string CompanyName; public string ContactName; public string ContactTitle; public string Address; public string City; public string Country; } 然后使用ExcelDataStorage提取logging如下: ExcelStorage provider = new ExcelStorage(typeof(CustomersVerticalBar)); provider.StartRow = 3; provider.StartColumn = 2; provider.FileName = "Customers.xls"; CustomerVerticalBar[] res = (CustomerVerticalBar[]) provider.ExtractRecords(); 问题是,如果没有inputExcel文件,但input只能从上传的文件(例如HttpPostedFileBase)中作为inputstream使用,那么ExcelDataStorage只将文件名作为input,而不是input文件名inputstream? 如果解决scheme使用ExcelDataStorage以外的其他类,那么也行。

“文件已经在使用错误”来了,但只有当它在Excel中打开

我正在使用Filehelpers来读取日志文件。 为了安全起见,我想确保它不会抛出“File Already in use”错误。 日志parsing过程启动时,日志logging器的清理可能仍然存在, 我正在使用filehelpers“ReadFileAsDT”方法并传递它的文件名。 我经历了源​​代码,发现它是以只读模式打开文件是正确的。 var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize, FileOptions.SequentialScan); this.Init(stream, encoding, detectEncodingFromByteOrderMarks, bufferSize); 但是,仍然只是为了确保我保持在Excel中打开日志文件。 并运行日志parsing器。 它给了“使用中的文件错误”。 如果我在记事本,写字板或记事本++中保持打开文件,则不会出现此错误。 excel打开文件的方式有什么特别之处吗?

如何使用C#/ FileHelpers ExcelNPOIStorage从Excel文件中提取数据

我正在尝试从Excelhelp Excel存储中提取数据。 所以我创build了一个类: public static class UalExcelReader { public static UalShipmentRecord[] ReadInput(String pathToFile) { var provider = new ExcelNPOIStorage(typeof (UalShipmentRecord)) { StartRow = 2, StartColumn = 1, FileName = pathToFile }; var res = (UalShipmentRecord[]) provider.ExtractRecords(); return res; } } 当然还有模范课: [DelimitedRecord("|")] public class UalShipmentRecord { public string contentofcol1; public string contentofcol2; … } 但是我得到一个IndexOutOfRangeException调用ExtractRecords(): […]

使用FileHelpers使用MVC 5导入Excel数据

我正在尝试在MVC 5中编写一个应用程序,该应用程序将接受用户指定的文件并将该文件信息上载到数据库中。 该文件本身有多个工作表,我认为FileHelpers正常处理,但我找不到任何关于使用字节数组的好文档。 我可以很好地获取文件,并find我的控制器,但不知道从哪里去。 我目前正在控制器中执行此操作: public ActionResult UploadFile(string filepath) { //we want to check here that the first file in the request is not null if (Request.Files[0] != null) { var file = Request.Files[0]; byte[] data = new byte[file.ContentLength]; ParseInputFile(data); //file.InputStream.Read(data, 0, data.Length); } ViewBag.Message = "Success!"; return View("Index"); } private void ParseInputFile(byte[] data) { […]