回复 5楼wzw的帖子
有反馈了:
您1#的做法是思路对的,请参考下面这段代码把SpanBorder设置为1试试:
C#.net代码
- //导入Excel后,如何把边框置为1(看起来细一些)
- //Step 1: 先把不是合并Cell的边框修改为1
- foreach (StyleInfo item in this.FpSpread1.Sheets[0].NamedStyles)
- {
- if (item.Border.BorderSizeTop > 1)
- {
- item.Border.BorderSizeTop = 1;
- }
- if (item.Border.BorderSizeBottom > 1)
- {
- item.Border.BorderSizeBottom = 1;
- }
- if (item.Border.BorderSizeLeft > 1)
- {
- item.Border.BorderSizeLeft = 1;
- }
- if (item.Border.BorderSizeRight > 1)
- {
- item.Border.BorderSizeRight = 1;
- }
- }
- //Step2: 再把是合并Cell的边框修改为1 SpanModel
- DefaultSheetSpanModel model = (DefaultSheetSpanModel)FpSpread1.ActiveSheetView.SpanModel;
- IEnumerator ien = model.GetEnumerator();
- bool b1 = ien.MoveNext();
- while (b1)
- {
- CellRange cr = (CellRange)ien.Current;
- FpSpread1.Sheets[0].Cells[cr.Row, cr.Column].Border.BorderSizeRight = 1;
- FpSpread1.Sheets[0].Cells[cr.Row, cr.Column].Border.BorderSizeTop = 1;
- FpSpread1.Sheets[0].Cells[cr.Row, cr.Column].Border.BorderSizeLeft = 1;
- FpSpread1.Sheets[0].Cells[cr.Row, cr.Column].Border.BorderSizeBottom = 1;
- b1 = ien.MoveNext(); //下一个合并单元格
- }
复制代码
通过在线转化工具转化后的VB.net代码:(供参考)
- '导入Excel后,如何把边框置为1(看起来细一些)
- 'Step 1: 先把不是合并Cell的边框修改为1
- For Each item As StyleInfo In Me.FpSpread1.Sheets(0).NamedStyles
- If item.Border.BorderSizeTop > 1 Then
- item.Border.BorderSizeTop = 1
- End If
- If item.Border.BorderSizeBottom > 1 Then
- item.Border.BorderSizeBottom = 1
- End If
- If item.Border.BorderSizeLeft > 1 Then
- item.Border.BorderSizeLeft = 1
- End If
- If item.Border.BorderSizeRight > 1 Then
- item.Border.BorderSizeRight = 1
- End If
- Next
- 'Step2: 再把是合并Cell的边框修改为1 SpanModel
- Dim model As DefaultSheetSpanModel = DirectCast(FpSpread1.ActiveSheetView.SpanModel, DefaultSheetSpanModel)
- Dim ien As IEnumerator = model.GetEnumerator()
- Dim b1 As Boolean = ien.MoveNext()
- While b1
- Dim cr As CellRange = DirectCast(ien.Current, CellRange)
- FpSpread1.Sheets(0).Cells(cr.Row, cr.Column).Border.BorderSizeRight = 1
- FpSpread1.Sheets(0).Cells(cr.Row, cr.Column).Border.BorderSizeTop = 1
- FpSpread1.Sheets(0).Cells(cr.Row, cr.Column).Border.BorderSizeLeft = 1
- FpSpread1.Sheets(0).Cells(cr.Row, cr.Column).Border.BorderSizeBottom = 1
- '下一个合并单元格
- b1 = ien.MoveNext()
- End While
复制代码
原理,找出Merge的Cell,逐个把Border修改为1, 借鉴了您的思路。 |