protected override void EndProcessing() { if (!File.Exists(outputPath) || ShouldProcess(outputPath, "Export-OpenXmlSpreadsheet")) { using (OpenXmlMemoryStreamDocument streamDoc = OpenXmlMemoryStreamDocument.CreateSpreadsheetDocument()) { using (SpreadsheetDocument document = streamDoc.GetSpreadsheetDocument()) { if (processedObjects.Count > 0) { List <string> headerList = new List <string>(); foreach (PSPropertyInfo propertyInfo in processedObjects[0].Properties) { headerList.Add(propertyInfo.Name.ToUpper()); } // Stores into a matrix all properties of objects passed as parameter int rowLength = headerList.Count; int rowCount = processedObjects.Count; string[][] valueMatrix = new string[rowCount][]; int currentRow = 0, currentColumn = 0; foreach (PSObject obj in processedObjects) { currentColumn = 0; valueMatrix[currentRow] = new string[rowLength]; foreach (PSPropertyInfo propertyInfo in obj.Properties) { try { if (propertyInfo.Value != null) { valueMatrix[currentRow][currentColumn] = propertyInfo.Value.ToString(); } } // Suppress errors on properties that cannot be read, but write the information to debug output. catch (GetValueInvocationException e) { WriteDebug(string.Format(CultureInfo.InvariantCulture, "Exception ({0}) at Object {1}, property {2}", e.Message, currentRow, currentColumn)); } currentColumn++; } currentRow++; } if (displayChart) { SpreadsheetDocumentManager.Create(document, headerList, valueMatrix, chartType, headerColumn, columnsToChart, initialRow); } else { SpreadsheetDocumentManager.Create(document, headerList, valueMatrix, initialRow); } } } OpenXmlPowerToolsDocument output = streamDoc.GetModifiedDocument(); output.FileName = outputPath; OutputDocument(output); } } }
void SaveDocument(IDocumentInfo documentInfo, bool checkModificationTime) { long itemId = ParseDocumentIdFromEditor(documentInfo.DocumentId); Item docItem = DataService.FindItemById(itemId); if (docItem == null || checkModificationTime && documentInfo.LastModifyTime < docItem.LastWriteTime) { return; } byte[] content = null; if (IsRichEditDocument(docItem)) { RichEditDocumentInfo richEditDocument = (RichEditDocumentInfo)documentInfo; content = richEditDocument.SaveCopy(RichEditDocumentManager.GetFormat(docItem)); } else if (IsSpreadsheetDocument(docItem)) { SpreadsheetDocumentInfo spreadsheetDocument = (SpreadsheetDocumentInfo)documentInfo; content = spreadsheetDocument.SaveCopy(SpreadsheetDocumentManager.GetFormat(docItem)); } else { throw new Exception("Incorrect document format."); } docItem.UpdateContent(content); DataService.SaveChanges(); }
public DocumentService(DocumentsApp app) : base(app) { RichEditDocumentManager = new RichEditDocumentManager(app); SpreadsheetDocumentManager = new SpreadsheetDocumentManager(app); Managers = new List <DocumentManagerBase>(); Managers.Add(RichEditDocumentManager); Managers.Add(SpreadsheetDocumentManager); Managers.Add(new UnsupportedDocumentManager(app)); LockedDocumentRegistry = new ConcurrentDictionary <long, User>(); }
public DevExpress.Spreadsheet.DocumentFormat GetSpreadsheetDocumentFormat(Item document) { return(SpreadsheetDocumentManager.GetFormat(document)); }
public bool IsSpreadsheetDocument(Item documentItem) { return(SpreadsheetDocumentManager.CanProcess(documentItem)); }