/// <summary> /// Insert Xml serialized presentation text in a worksheet and append it to presenatation workbook /// </summary> /// <param name="Presentation">Preesnataion Class Instance TablePresentation / Map</param> /// <param name="PresentationPath">Full path of presentation file</param> /// <param name="presentationType">PresentationType enum value. Table / Graph / Map</param> public static void InsertSelectionSheet(object Presentation, string PresentationPath, PresentationType presentationType) { string SerializedText = string.Empty; DIExcel DIExcel = new DIExcel(PresentationPath); DIExcel.InsertWorkSheet(SELECTION_WORKSHEET_NAME); int SelectionWorksheetIndex = DIExcel.GetSheetIndex(SELECTION_WORKSHEET_NAME); //-- Upadte the user selection GIds before inserting them in selections sheet //-- Retrieve serialized text switch (presentationType) { case PresentationType.Table: SerializedText = ((TablePresentation)Presentation).GetSerializedText(true); break; case PresentationType.Graph: if (((GraphPresentation)Presentation).TablePresentation.UserPreference.General.ShowExcel) { SelectionWorksheetIndex -= 1; } SerializedText = ((GraphPresentation)Presentation).GetSerializedText(); break; case PresentationType.Map: SerializedText = ((Map.Map)Presentation).GetSerializedText(true); break; } //Insert Serialized Text into worksheet // Single excel cell can hold at the most 32000 characters // If length of serialized text is greater than 32000 char then break them and place them in multiple cells //TODO Use this logic for Table and graph also and update GetSerializedPresentationText() function accordingly if (SerializedText.Length > 32000) { int i = 0; //Calculating and Iterating number of 32000 Characters slots in Text //-- Set First column format type as "TEXT" DIExcel.SetColumnFormatType("A:A", SelectionWorksheetIndex, SpreadsheetGear.NumberFormatType.Text); while (i < Math.Floor((double)(SerializedText.Length / 32000))) { //'Adding next 32000 Charcters each time at i row. if (i == 160) { } DIExcel.SetCellValue(SelectionWorksheetIndex, i, 0, SerializedText.Substring(32000 * i, 32000)); i += 1; } DIExcel.SetCellValue(SelectionWorksheetIndex, i, 0, SerializedText.Substring(32000 * i)); } else { DIExcel.SetCellValue(SelectionWorksheetIndex, 0, 0, SerializedText); } //-- Hide the selection sheet. DIExcel.HideWorksheet(SELECTION_WORKSHEET_NAME); DIExcel.ActiveSheetIndex = 0; DIExcel.Save(); DIExcel.Close(); }