回复 7楼Alice的帖子
你好 我在导出里做了处理,解决了部分问题,但是还是有部分没有解决,代码如下
- using (var stream = dialog.OpenFile())
- {
- C1FlexGrid flex = new C1FlexGrid();
- flex.ItemsSource = grid.ItemsSource;
- flex.ColumnHeaders.Rows.Add(new C1.Silverlight.FlexGrid.Row());
- C1XLBook book = new C1XLBook();
- book.Sheets.Clear();
- XLSheet xlSheet = book.Sheets.Add("Sheet1");
-
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < grid.Columns.Count; j++)
- {
- List<string> lscolHeader = (List<string>)(grid.Columns[j].Header);
- string colHeader = "";
- if (lscolHeader.Count > i)
- colHeader = lscolHeader[i];
- flex.ColumnHeaders[i, j] = colHeader;
- }
- }
- //合并列
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < grid.Columns.Count; j++)
- {
- if (i == 0 && (flex.ColumnHeaders[i, j].ToString() == "" || flex.ColumnHeaders[i + 1, j].ToString() == "" || flex.ColumnHeaders[i, j].ToString() == flex.ColumnHeaders[i + 1, j].ToString()))//第一行
- {
- xlSheet.MergedCells.Add(new XLCellRange(i, i + 1, j, j));
- }
- }
- }
- //并行
- for (int j = 0; j < grid.Columns.Count; j++)
- {
- int lastColumNum = j;
- for (int m = j + 1; m < grid.Columns.Count; m++)
- {
- if (flex.ColumnHeaders[0, j].ToString() == flex.ColumnHeaders[0, m].ToString())
- {
- lastColumNum = m;
- }
- }
- if (lastColumNum > j)
- {
- xlSheet.MergedCells.Add(new XLCellRange(0, 0, j, lastColumNum));
- j = lastColumNum;
- }
- }
复制代码
现在表头我已经合并完成了,我想在表头上方添加一行标题,其实就是添加和相同列数的单元格做合并,和内容结束后插入一行写时间,改如何添加呢?
|