/// <summary> /// 单元格大小比较,用于排序 /// </summary> /// <param name="cell">比较单元格</param> /// <returns>1:较大 0:相等 -1:较小</returns> public override int compareTo(FCGridCell cell) { String target = cell.getString(); String value = getString(); if (value != null) { return(value.CompareTo(target)); } return(-1); }
/// <summary> /// 导出到Txt /// </summary> /// <param name="fileName">文件名</param> /// <param name="grid">表格控件</param> public static void exportToTxt(String fileName, FCGrid grid) { StringBuilder sb = new StringBuilder(); List <FCGridColumn> columns = grid.m_columns; int columnsSize = columns.Count; for (int i = 0; i < columnsSize; i++) { sb.Append(columns[i].Text); if (i != columnsSize - 1) { sb.Append(","); } } List <FCGridRow> rows = grid.m_rows; int rowsSize = rows.Count; List <FCGridRow> visibleRows = new List <FCGridRow>(); for (int i = 0; i < rowsSize; i++) { if (rows[i].Visible) { visibleRows.Add(rows[i]); } } int visibleRowsSize = visibleRows.Count; if (visibleRowsSize > 0) { sb.Append("\r\n"); for (int i = 0; i < visibleRowsSize; i++) { for (int j = 0; j < columnsSize; j++) { FCGridCell cell = visibleRows[i].getCell(j); String cellValue = cell.getString(); sb.Append(cellValue); if (j != columnsSize - 1) { sb.Append(","); } } if (i != visibleRowsSize - 1) { sb.Append("\r\n"); } } } DataCenter.ExportService.ExportHtmlToTxt(fileName, sb.ToString()); }
/// <summary> /// 导出到Excel /// </summary> /// <param name="path">路径</param> public static void exportToExcel(String fileName, FCGrid grid) { DataTable dataTable = new DataTable(); List <FCGridColumn> columns = grid.m_columns; int columnsSize = columns.Count; for (int i = 0; i < columnsSize; i++) { dataTable.Columns.Add(new DataColumn(columns[i].Text)); } List <FCGridRow> rows = grid.m_rows; int rowsSize = rows.Count; for (int i = 0; i < rowsSize; i++) { if (rows[i].Visible) { DataRow dr = dataTable.NewRow(); for (int j = 0; j < columnsSize; j++) { FCGridCell cell = grid.m_rows[i].getCell(j); if (cell is FCGridStringCell) { dr[j] = cell.getString(); } else { dr[j] = cell.getDouble(); } } dataTable.Rows.Add(dr); } } DataCenter.ExportService.ExportDataTableToExcel(dataTable, fileName); dataTable.Dispose(); }