/// <summary> /// Logs messages using NotificationReceiver /// </summary> /// <param name="fileName"></param> public static void LoggerWithExtractorFactory(string fileName) { //ExStart:LoggerWithExtractorFactory //get file actual path String filePath = Common.GetFilePath(fileName); var receiverForFactory = new NotificationReceiver(); var factory = new ExtractorFactory(null, null, null, receiverForFactory); var receiver = new NotificationReceiver(); LoadOptions loadOptions = new LoadOptions(); loadOptions.NotificationReceiver = receiver; using (var extractor = new CellsTextExtractor(filePath, loadOptions)) { Console.WriteLine(extractor.ExtractAll()); } //ExEnd:LoggerWithExtractorFactory }
public ActionResult ExtractRowAndColumn([FromBody] string fileName, [FromBody] int rowIndex, [FromBody] string columnIndex) { List <string> extractedText = new List <string>(); ExtractorFactory factory = new ExtractorFactory(); string filePath = Server.MapPath("../App_Data//Uploads//" + fileName); try { CellsTextExtractor extractor = new CellsTextExtractor(filePath); int sheetIndex = 0; CellsSheetInfo sheetInfo = extractor.GetSheetInfo(sheetIndex); extractedText.Add(sheetInfo.ExtractRow(rowIndex, columnIndex)); } catch (Exception ex) { extractedText.Add(ex.Message); } return(Json(extractedText, JsonRequestBehavior.AllowGet)); }
private IDocumentContentExtractor GetContentExtractor(string inFilePath, string fileExt) { IDocumentContentExtractor extractor = null; if (Array.Exists(WordTypesForImage, E => E == fileExt)) { extractor = new WordsTextExtractor(inFilePath); } else if (Array.Exists(ExcelTypesForImage, E => E == fileExt)) { extractor = new CellsTextExtractor(inFilePath); } else if (Array.Exists(SlidesTypesForImage, E => E == fileExt)) { extractor = new SlidesTextExtractor(inFilePath); } else if (Array.Exists(PdfTypesForImage, E => E == fileExt)) { extractor = new PdfTextExtractor(inFilePath); } return(extractor); }
/// <summary> /// Logs messages using NotificationReceiver /// </summary> /// <param name="fileName"></param> public static void LoggerWithManualExceptionHandling(string fileName) { //ExStart:LoggerWithManualExceptionHandling //get file actual path String filePath = Common.GetFilePath(fileName); var receiver = new NotificationReceiver(); LoadOptions loadOptions = new LoadOptions(); loadOptions.NotificationReceiver = receiver; try { using (var extractor = new CellsTextExtractor(filePath, loadOptions)) { Console.WriteLine(extractor.ExtractAll()); } } catch (Exception ex) { receiver.ProcessMessage(NotificationMessage.CreateErrorMessage(ex.Message, ex)); } //ExEnd:LoggerWithManualExceptionHandling }
private async Task <Response> ParseFileText(string fileName, string folderName) { string logMsg = "ControllerName: GroupDocsParserController FileName: " + fileName + " FolderName: " + folderName; try { return(await ProcessTask(fileName, folderName, ".txt", false, "", delegate(string inFilePath, string outPath, string zipOutFolder) { EncodingDetector detector = new EncodingDetector(Encoding.GetEncoding(1251)); if (!Directory.Exists(zipOutFolder)) { Directory.CreateDirectory(zipOutFolder); } using (Stream stream = new FileStream(inFilePath, FileMode.Open)) { System.IO.File.WriteAllText(outPath, "Encoding: " + detector.Detect(stream, true) + Environment.NewLine); } ExtractorFactory factory = new ExtractorFactory(); MetadataExtractor metadataExtractor = factory.CreateMetadataExtractor(inFilePath); if (metadataExtractor != null) { MetadataCollection metadataCollection = metadataExtractor.ExtractMetadata(inFilePath); System.IO.File.AppendAllText(outPath, Environment.NewLine + "Metadata:" + Environment.NewLine); foreach (string key in metadataCollection.Keys) { System.IO.File.AppendAllText(outPath, string.Format("{0} = {1}", key, metadataCollection[key]) + Environment.NewLine); } } System.IO.File.AppendAllText(outPath, Environment.NewLine + "Parsed content:" + Environment.NewLine); string fileExt = Path.GetExtension(fileName).Substring(1).ToLower(); if (GetFormatType(fileExt) == FormatType.Excel) { CellsTextExtractor extractor = new CellsTextExtractor(inFilePath); extractor.ExtractMode = ExtractMode.Standard; for (int sheetIndex = 0; sheetIndex < extractor.SheetCount; sheetIndex++) { System.IO.File.AppendAllText(outPath, Environment.NewLine + "Sheet # " + extractor.SheetCount + Environment.NewLine); System.IO.File.AppendAllText(outPath, extractor.ExtractSheet(sheetIndex)); } } else { TextExtractor textExtractor = factory.CreateFormattedTextExtractor(inFilePath); if (textExtractor == null) { textExtractor = factory.CreateTextExtractor(inFilePath); } System.IO.File.AppendAllText(outPath, textExtractor.ExtractAll()); } })); } catch (Exception exc) { return(new Response { FileName = fileName, FolderName = folderName, OutputType = "txt", Status = exc.Message, StatusCode = 500, Text = exc.ToString() }); } }