鱼dotNet 2023-11-03 18:27 采纳率: 0%
浏览 208

为什么NPOI导出的Excel表格单元格都是虚线

如图,C#使用NPOI导出的表格,已经设置cellstyle的上下左右都为无边框,但出来的单元格都是虚线边框,并且在WPS里面设置为无边框也还是一样效果,请教如何使导出的单元格为普通不带边框的效果?

public static XSSFWorkbook ToXSSFWorkbook(DataSet dataset)
        {
            var workbook = new XSSFWorkbook();
            ISheet sheet;
            DataTable table;
            ICellStyle style = workbook.CreateCellStyle();
            style.BorderBottom = BorderStyle.None;
            style.BorderLeft = BorderStyle.None;
            style.BorderRight = BorderStyle.None;
            style.BorderTop = BorderStyle.None;
            for (int i = 0; i < dataset.Tables.Count; i++)
            {
                table = dataset.Tables[i];
                sheet = workbook.CreateSheet(table.TableName);
                DataTableToXlsSheet(table, style, ref sheet);
            }
            return workbook;
        }

        private static void DataTableToXlsSheet(DataTable table, ICellStyle style,ref ISheet sheet)
        {
            DataRow dataRow;
            IRow row;
            ICell cell;
            int cols = table.Columns.Count;
            int rows = table.Rows.Count;

            //写入第一行,数据表头;
            row = sheet.CreateRow(0);
            for (int i = 0; i < cols; i++)
            {
                cell = row.CreateCell(i);
                cell.CellStyle = style;
                SetCellValue(ref cell, table.Columns[i].ColumnName);
            }
            //写数据
            for (int i = 0; i < rows; i++)
            {
                dataRow = table.Rows[i];
                row = sheet.CreateRow(i + 1);
                for (int j = 0; j < cols; j++)
                {
                    cell = row.CreateCell(j);
                    SetCellValue(ref cell, dataRow[j]);
                }
            }
        }

img

  • 写回答

2条回答 默认 最新

  • 鱼dotNet 2023-11-04 09:38
    关注

    然后发现,用office Excel打开文件,边框是无边框的效果,但是用WPS打开时是虚线效果,有人知道这个是什么原因吗?

    评论

报告相同问题?

问题事件

  • 创建了问题 11月3日