/// <summary> /// Example5s this instance. /// </summary> /** <example><para></para> * <code> var files = folderResources.findFiles("*.bib*", SearchOption.AllDirectories); * var targetFolder = folderResults.Add("WithoutTemplate", "Without template", "Exporting Excel files without column data annotation template"); * BibTexTools.ExportToExcel(files, notation, log, null, targetFolder); * targetFolder = folderResults.Add("WithTemplate", "With template", "Exporting Excel files with column data annotation template"); * // creating template from Type * propertyAnnotationPreset template = new propertyAnnotationPreset(typeof(BibTexEntryModel)); * template.defaultItem.definitions.Add(templateFieldDataTable.columnWidth, 10); * template.defaultItem.definitions.Add(templateFieldDataTable.col_color, "#FF6600"); * BibTexTools.ExportToExcel(files, notation, log, template, targetFolder); </code> * </example> */ public void Example5_SpecifyFormattingManually() { var files = folderResources.findFiles("*.bib*", SearchOption.AllDirectories); var targetFolder = folderResults.Add("WithoutTemplate", "Without template", "Exporting Excel files without column data annotation template"); BibTexTools.ExportToExcel(files, notation, log, null, targetFolder); targetFolder = folderResults.Add("WithTemplate", "With template", "Exporting Excel files with column data annotation template"); // creating template from Type propertyAnnotationPreset template = new propertyAnnotationPreset(typeof(BibTexEntryModel)); template.defaultItem.definitions.Add(templateFieldDataTable.columnWidth, 10); template.defaultItem.definitions.Add(templateFieldDataTable.col_color, "#FF6600"); template.GetAnnotationPresetItem(nameof(BibTexEntryModel.journal)).definitions.Add(templateFieldDataTable.col_color, Color.Red); BibTexTools.ExportToExcel(files, notation, log, template, targetFolder); }
/// <summary> /// Exports all acceptable file formats, to excel tables with the same name /// </summary> /// <param name="filePaths">The file paths.</param> /// <param name="author">The author.</param> /// <param name="log">The log.</param> /// <returns></returns> public static List <DataTableForStatistics> ExportToExcel(IEnumerable <String> filePaths, aceAuthorNotation author, ILogBuilder log = null, propertyAnnotationPreset customTemplate = null, folderNode outputFolder = null) { List <DataTableForStatistics> output = new List <DataTableForStatistics>(); Int32 c = 0; if (ExportInParallel) { Stack <DataTableForStatistics> outputStack = new Stack <DataTableForStatistics>(); Parallel.ForEach(filePaths, x => { if (CheckExtension(x)) { var excel = ExportToExcel(x, author, log, customTemplate, outputFolder); outputStack.Push(excel); c = 0; } else { c++; } }); output.AddRange(outputStack.ToArray()); } else { foreach (String f in filePaths) { //if (c > FileExtensionAbortCount) //{ // if (log != null) log.log("File list aborted after [" + c.ToString() + "] incompatibile files"); // break; //} if (CheckExtension(f)) { output.Add(ExportToExcel(f, author, log, customTemplate, outputFolder)); c = 0; } else { c++; } } } return(output); }
/// <summary> /// Loads the BibTex file and converts it to Excel /// </summary> /// <param name="filePath">The file path.</param> /// <param name="author">The author.</param> /// <param name="log">The log.</param> /// <param name="customTemplate">Custom data annotation template, to be used for Excel file generation. If not specified, default <see cref="template"/> is used</param> /// <returns>Extended DataTable that is written in Excel file</returns> public static DataTableForStatistics ExportToExcel(String filePath, aceAuthorNotation author, ILogBuilder log = null, propertyAnnotationPreset customTemplate = null, folderNode outputFolder = null) { BibTexDataFile bibFile = new BibTexDataFile(filePath); FileInfo fi = new FileInfo(filePath); if (outputFolder == null) { outputFolder = fi.Directory; } if (customTemplate == null) { customTemplate = template; } DataTable reportTable = bibFile.ConvertToDataTable(null, customTemplate, log); //.GetReportAndSave(fi.Directory, author, bibFile.name); DataTableForStatistics report = reportTable.GetReportAndSave(outputFolder, author); if (log != null) { log.log("BibTex [" + filePath + "] -> Excel [" + report.lastFilePath + "]"); } return(report); }
/// <summary> /// Builds data table - from BibTex entries /// </summary> /// <param name="tagsFilter">List of tag names to include as columns. Include all found, if null</param> /// <returns></returns> public DataTable ConvertToDataTable(List <String> tagsFilter = null, propertyAnnotationPreset preset = null, ILogBuilder log = null) { DataTable output = new DataTable(); output.SetTitle(name); List <String> fieldsToUse = new List <string>(); if (tagsFilter == null) { fieldsToUse.AddRange(fields); } else { foreach (String field in fields) { if (tagsFilter.Contains(field)) { fieldsToUse.Add(field); } } } foreach (String field in fieldsToUse) { DataColumn dc = output.Columns.Add(field); // dc.SetDefaultBackground(ColorWorks.ColorLightGray); } if (preset != null) { output.SetAdditionalInfoEntry("Format template", preset.name); preset.DeployTo(output, false, log); } foreach (BibTexEntryBase ent in UntypedEntries) { var row = output.NewRow(); foreach (String field in fieldsToUse) { if (field == typeColumn) { row[typeColumn] = ent.type; } else if (field == keyColumn) { row[keyColumn] = ent.Key; } else { row[field] = ent.Get(field); } } output.Rows.Add(row); } output.SetDescription("BibTex bibliography entries, converted to table using imbSCI.Tools library"); output.SetAdditionalInfoEntry("Source file", sourcePath); output.SetAdditionalInfoEntry("Conversion date", DateTime.Now.ToShortDateString()); return(output); }