//internal ExcelPivotTableField _field; internal ExcelPivotTableSlicer(ExcelDrawings drawings, XmlNode node, ExcelPivotTableField field, ExcelGroupShape parent = null) : base(drawings, node, parent) { _ws = drawings.Worksheet; //_field = field; var name = drawings.Worksheet.Workbook.GetSlicerName(field.Cache.Name); CreateDrawing(name); SlicerName = name; Caption = field.Name; RowHeight = 19; if (field.Slicer == null) { CacheName = "Slicer_" + ExcelAddressUtil.GetValidName(name); var cache = new ExcelPivotTableSlicerCache(NameSpaceManager); if (field.Slicer == null) { field.Slicer = this; } cache.Init(drawings.Worksheet.Workbook, name, field); _cache = cache; } else { CacheName = field.Slicer.Cache.Name; _cache = field.Slicer.Cache; } //If items has not been init, refresh! if (field._items == null) { field.Items.Refresh(); } }
internal static void FormatAsTable(ExcelRangeBase range, TableStyles tableStyle, string tableName, bool autoFitColumns = true) { string escapedTableName = ExcelAddressUtil.GetValidName(tableName); //format the table var table = range.Worksheet.Tables.Add(range, escapedTableName); table.TableStyle = tableStyle; if (autoFitColumns) { range.AutoFitColumns(); } }
internal void Init(ExcelWorkbook wb, string name, ExcelPivotTableField field) { if (wb._slicerCaches == null) { wb.LoadSlicerCaches(); } CreatePart(wb); TopNode = SlicerCacheXml.DocumentElement; Name = "Slicer_" + ExcelAddressUtil.GetValidName(name); _field = field; SourceName = _field.Cache.Name; wb.Names.AddFormula(Name, "#N/A"); PivotTables.Add(_field._pivotTable); CreateWorkbookReference(wb, ExtLstUris.WorkbookSlicerPivotTableUri); SlicerCacheXml.Save(Part.GetStream()); Data.Items.Refresh(); }
private string GetStartXml(string name, int tblId) { name = ConvertUtil.ExcelEscapeString(name); string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>"; xml += string.Format("<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"{0}\" name=\"{1}\" displayName=\"{2}\" ref=\"{3}\" headerRowCount=\"1\">", tblId, name, ExcelAddressUtil.GetValidName(name), Address.Address); xml += string.Format("<autoFilter ref=\"{0}\" />", Address.Address); int cols = Address._toCol - Address._fromCol + 1; xml += string.Format("<tableColumns count=\"{0}\">", cols); var names = new Dictionary <string, string>(); for (int i = 1; i <= cols; i++) { var cell = WorkSheet.Cells[Address._fromRow, Address._fromCol + i - 1]; string colName; if (cell.Value == null || names.ContainsKey(cell.Value.ToString())) { //Get an unique name int a = i; do { colName = string.Format("Column{0}", a++); }while (names.ContainsKey(colName)); } else { colName = SecurityElement.Escape(cell.Value.ToString()); } names.Add(colName, colName); xml += string.Format("<tableColumn id=\"{0}\" name=\"{1}\" />", i, colName); } xml += "</tableColumns>"; xml += "<tableStyleInfo name=\"TableStyleMedium9\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\" /> "; xml += "</table>"; return(xml); }
internal ExcelTableSlicer(ExcelDrawings drawings, XmlNode node, ExcelTableColumn column) : base(drawings, node) { TableColumn = column; if (column.Slicer == null) { column.Slicer = this; } var name = drawings.Worksheet.Workbook.GetSlicerName(column.Name); CreateDrawing(name); SlicerName = name; Caption = column.Name; RowHeight = 19; CacheName = "Slicer_" + ExcelAddressUtil.GetValidName(name); var cache = new ExcelTableSlicerCache(NameSpaceManager); cache.Init(column, CacheName); _cache = cache; }