forked from ARLM-Keller/SpreadsheetLight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPivotTableFunctions.cs
More file actions
238 lines (201 loc) · 9.79 KB
/
PivotTableFunctions.cs
File metadata and controls
238 lines (201 loc) · 9.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
using System;
using System.Collections.Generic;
using System.Linq;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
namespace SpreadsheetLight
{
public partial class SLDocument
{
//TODO
//public bool InsertPivotTable(SLPivotTable PivotTable, string CellReference)
//{
// int iRowIndex = -1;
// int iColumnIndex = -1;
// if (!SLTool.FormatCellReferenceToRowColumnIndex(CellReference, out iRowIndex, out iColumnIndex))
// {
// return false;
// }
// return InsertPivotTable(PivotTable, gsSelectedWorksheetName, iRowIndex, iColumnIndex, false);
//}
//public bool InsertPivotTable(SLPivotTable PivotTable, int RowIndex, int ColumnIndex)
//{
// return InsertPivotTable(PivotTable, gsSelectedWorksheetName, RowIndex, ColumnIndex, false);
//}
//public bool InsertPivotTable(SLPivotTable PivotTable, string NewWorksheetName, string CellReference)
//{
// int iRowIndex = -1;
// int iColumnIndex = -1;
// if (!SLTool.FormatCellReferenceToRowColumnIndex(CellReference, out iRowIndex, out iColumnIndex))
// {
// return false;
// }
// return InsertPivotTable(PivotTable, NewWorksheetName, iRowIndex, iColumnIndex, false);
//}
//public bool InsertPivotTable(SLPivotTable PivotTable, string NewWorksheetName, int RowIndex, int ColumnIndex)
//{
// return InsertPivotTable(PivotTable, NewWorksheetName, RowIndex, ColumnIndex, false);
//}
//public bool InsertPivotTable(SLPivotTable PivotTable, string NewWorksheetName, string CellReference, bool SelectNewWorksheet)
//{
// int iRowIndex = -1;
// int iColumnIndex = -1;
// if (!SLTool.FormatCellReferenceToRowColumnIndex(CellReference, out iRowIndex, out iColumnIndex))
// {
// return false;
// }
// return InsertPivotTable(PivotTable, NewWorksheetName, iRowIndex, iColumnIndex, false);
//}
//public bool InsertPivotTable(SLPivotTable PivotTable, string NewWorksheetName, int RowIndex, int ColumnIndex, bool SelectNewWorksheet)
//{
// // the upper limits are checked for consistency (well, for fun basically).
// // In actuality, if the pivot table is set at the bottom/right of the worksheet,
// // there's nothing to show anyway.
// if (RowIndex < 1) RowIndex = 1;
// if (RowIndex > SLConstants.RowLimit) RowIndex = SLConstants.RowLimit;
// if (ColumnIndex < 1) ColumnIndex = 1;
// if (ColumnIndex > SLConstants.ColumnLimit) ColumnIndex = SLConstants.ColumnLimit;
// if (!PivotTable.IsValid) return false;
// if (!SLTool.CheckSheetChartName(NewWorksheetName))
// {
// return false;
// }
// // Get cell data first
// Dictionary<SLCellPoint, SLCell> cells = new Dictionary<SLCellPoint, SLCell>();
// if (PivotTable.IsDataSourceTable)
// {
// //TODO
// }
// else
// {
// // else data source is from worksheet, and we're taking that as the current worksheet.
// List<SLCellPoint> currentpts = slws.Cells.Keys.ToList<SLCellPoint>();
// foreach (SLCellPoint currentpt in currentpts)
// {
// if (PivotTable.DataRange.StartRowIndex <= currentpt.RowIndex
// && currentpt.RowIndex <= PivotTable.DataRange.EndRowIndex
// && PivotTable.DataRange.StartColumnIndex <= currentpt.ColumnIndex
// && currentpt.ColumnIndex <= PivotTable.DataRange.EndColumnIndex)
// {
// cells[currentpt] = slws.Cells[currentpt].Clone();
// }
// }
// }
// // keep the current worksheet name in case we have to select it again
// string sCurrentWorksheetName = gsSelectedWorksheetName;
// string sNewWorksheetName = NewWorksheetName;
// HashSet<string> hsSheetNames = new HashSet<string>();
// foreach (SLSheet sheet in slwb.Sheets)
// {
// // there shouldn't be name collisions, so we're not checking
// hsSheetNames.Add(sheet.Name);
// }
// if (hsSheetNames.Contains(sNewWorksheetName))
// {
// if (!sNewWorksheetName.Equals(gsSelectedWorksheetName, StringComparison.OrdinalIgnoreCase))
// {
// // an existing sheet name is used, but is not the current worksheet
// // So we must come up with a new name.
// int index = 1;
// sNewWorksheetName = string.Format("Sheet{0}", index);
// while (hsSheetNames.Contains(sNewWorksheetName))
// {
// ++index;
// sNewWorksheetName = string.Format("Sheet{0}", index);
// }
// // this automatically selects the worksheet too.
// AddWorksheet(sNewWorksheetName);
// }
// // else we just use the current worksheet.
// // Yup, that's it. Don't have to do anything else.
// }
// else
// {
// // this automatically selects the worksheet too.
// AddWorksheet(sNewWorksheetName);
// }
// int i, j, iSharedStringIndex;
// SLCell cell;
// SLCellPoint pt;
// SLRstType rst = new SLRstType();
// string sPlainString = string.Empty;
// Dictionary<int, string> dictSharedStringSimplified = new Dictionary<int, string>();
// HashSet<string> hsSharedItemString = new HashSet<string>();
// HashSet<double> hsSharedItemNumber = new HashSet<double>();
// HashSet<bool> hsSharedItemBoolean = new HashSet<bool>();
// // missing, error, datetime?
// PivotTableCacheDefinitionPart cachedef = wbp.AddNewPart<PivotTableCacheDefinitionPart>();
// #region Content for PivotCacheDefinition
// SLPivotCacheDefinition pcd = new SLPivotCacheDefinition();
// SLCellPointRange datarange = new SLCellPointRange();
// if (PivotTable.IsDataSourceTable)
// {
// //TODO source is a Table
// }
// else
// {
// pcd.CacheSource.IsWorksheetSource = true;
// pcd.CacheSource.WorksheetSourceReference = SLTool.TranslateCellPointRangeToReference(PivotTable.Location.Reference);
// pcd.CacheSource.WorksheetSourceSheet = gsSelectedWorksheetName;
// datarange.StartRowIndex = PivotTable.Location.Reference.StartRowIndex;
// datarange.StartColumnIndex = PivotTable.Location.Reference.StartColumnIndex;
// datarange.EndRowIndex = PivotTable.Location.Reference.EndRowIndex;
// datarange.EndColumnIndex = PivotTable.Location.Reference.EndColumnIndex;
// }
// SLCacheField cfTemp;
// for (j = datarange.StartColumnIndex; j <= datarange.EndColumnIndex; ++j)
// {
// pt = new SLCellPoint(datarange.StartRowIndex, j);
// if (cells.ContainsKey(pt))
// {
// cfTemp = new SLCacheField();
// cell = cells[pt];
// if (cell.DataType == CellValues.SharedString)
// {
// if (cell.CellText != null) iSharedStringIndex = Convert.ToInt32(cell.CellText);
// else iSharedStringIndex = Convert.ToInt32(cell.NumericValue);
// if (dictSharedStringSimplified.ContainsKey(iSharedStringIndex))
// {
// cfTemp.Name = dictSharedStringSimplified[iSharedStringIndex];
// }
// else
// {
// rst.FromHash(listSharedString[iSharedStringIndex]);
// sPlainString = rst.ToPlainString();
// dictSharedStringSimplified[iSharedStringIndex] = sPlainString;
// cfTemp.Name = sPlainString;
// }
// }
// else if (cell.DataType == CellValues.Number)
// {
// }
// else if (cell.DataType == CellValues.Boolean)
// {
// }
// else
// {
// }
// }
// else
// {
// }
// }
// cachedef.PivotCacheDefinition = pcd.ToPivotCacheDefinition();
// #endregion Content for PivotCacheDefinition
// PivotTableCacheRecordsPart cacherecords = cachedef.AddNewPart<PivotTableCacheRecordsPart>();
// #region Content for PivotCacheRecords
// #endregion Content for PivotCacheRecords
// //TODO check string.isNull for relID
// WorksheetPart wsp = (WorksheetPart)wbp.GetPartById(gsSelectedWorksheetRelationshipID);
// PivotTablePart ptp = wsp.AddNewPart<PivotTablePart>();
// #region Content for PivotTableDefinition
// #endregion Content for PivotTableDefinition
// ptp.AddPart(cachedef);
// if (!SelectNewWorksheet)
// {
// SelectWorksheet(sCurrentWorksheetName);
// }
// return false;
//}
}
}