public static void ExportGrid(DataGridView pGrid, string pFileNamePrefix) { object[] vHeader = new object[pGrid.ColumnCount]; string[] vFormat = new string[pGrid.ColumnCount]; ExlHAlign[] vHAlign = new ExlHAlign[pGrid.ColumnCount]; object[,] vData = new object[pGrid.RowCount, pGrid.ColumnCount]; int vColIndex = -1; /// for (int c = 0; c <= pGrid.ColumnCount - 1; c++) { if (pGrid.Columns[c].Visible == true && pGrid.Columns[c].Name != "FILLER") { vColIndex++; /// vHeader[vColIndex] = pGrid.Columns[c].HeaderText; /// vFormat[vColIndex] = pGrid.Columns[c].DefaultCellStyle.Format; /// switch (pGrid.Columns[c].DefaultCellStyle.Alignment) { default: case DataGridViewContentAlignment.TopLeft: case DataGridViewContentAlignment.BottomLeft: case DataGridViewContentAlignment.MiddleLeft: vHAlign[vColIndex] = ExlHAlign.xlHAlignLeft; break; case DataGridViewContentAlignment.TopRight: case DataGridViewContentAlignment.BottomRight: case DataGridViewContentAlignment.MiddleRight: vHAlign[vColIndex] = ExlHAlign.xlHAlignRight; break; case DataGridViewContentAlignment.TopCenter: case DataGridViewContentAlignment.BottomCenter: case DataGridViewContentAlignment.MiddleCenter: vHAlign[vColIndex] = ExlHAlign.xlHAlignCenter; break; } /// for (int r = 0; r <= pGrid.RowCount - 1; r++) { vData[r, vColIndex] = pGrid[c, r].FormattedValue; } } } /// Array.Resize <object>(ref vHeader, (vColIndex + 1)); Array.Resize <string>(ref vFormat, (vColIndex + 1)); Array.Resize <ExlHAlign>(ref vHAlign, (vColIndex + 1)); /// ExlUtil.Export(vHeader, vFormat, vHAlign, vData, pFileNamePrefix); }
public void ExportGrid(string pFileNamePrefix) { ExlUtil.ExportGrid(this, pFileNamePrefix); }