using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Docs.Excel; namespace FontAndFormat { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // TODO: If using Excel Reader .NET Full Version, put YOUR-LICENSE-CODE below. // Otherwise, if you are using Excel Reader .NET Trial, comment out the following line // (Free version doesn't have LicenseCode method). // Docs.Excel.ExcelWorkbook.SetLicenseCode("YOUR-LICENSE-CODE"); ExcelWorkbook Wbook = ExcelWorkbook.ReadXLS(@"..\..\..\FontAndFormat.xls"); // Uncomment for XLSX reading // ExcelWorkbook Wbook = ExcelWorkbook.ReadXLSX(@"..\..\..\FontAndFormat.xlsx"); // Create DataTabe object DataTable DataTable1 = new DataTable(); int NumberRow = Wbook.Worksheets[0].Rows.Count * Wbook.Worksheets[0].Columns.Count; for (int i = 0; i < NumberRow; i++) DataTable1.Rows.Add(DataTable1.NewRow()); DataTable1.Columns.Add("Cells ID"); DataTable1.Columns.Add("Text"); DataTable1.Columns.Add("Name"); DataTable1.Columns.Add("Size"); DataTable1.Columns.Add("Color"); DataTable1.Columns.Add("Bold"); DataTable1.Columns.Add("Italic"); DataTable1.Columns.Add("Underline"); DataTable1.Columns.Add("Strikeout"); DataTable1.Columns.Add("Subscript"); DataTable1.Columns.Add("Superscript"); DataTable1.Columns.Add("Rotation"); DataTable1.Columns.Add("StringFormat"); DataTable1.Columns.Add("HorizontalAlignment"); DataTable1.Columns.Add("VerticalAlignment"); // Get first Worksheet name string WorksheetName = Wbook.Worksheets[0].Name; // Filling DataTable int Count = 0; for (int i = 0; i < Wbook.Worksheets[0].Rows.Count; i++) { for (int j = 0; j < Wbook.Worksheets[0].Columns.Count; j++) { DataTable1.Rows[Count][0] = ExcelColumn.ColumnIndexToName(j + 1) + Convert.ToString(i + 1); DataTable1.Rows[Count][1] = Wbook.Worksheets[0].Cells[i, j].ValueWithFormat(); DataTable1.Rows[Count][2] = Wbook.Worksheets[0].Cells[i, j].Style.Font.Name; DataTable1.Rows[Count][3] = Wbook.Worksheets[0].Cells[i, j].Style.Font.Size; DataTable1.Rows[Count][4] = Wbook.Worksheets[0].Cells[i, j].Style.Font.Color; DataTable1.Rows[Count][5] = Wbook.Worksheets[0].Cells[i, j].Style.Font.Bold; DataTable1.Rows[Count][6] = Wbook.Worksheets[WorksheetName].Columns[j].Cells[i].Style.Font.Italic; DataTable1.Rows[Count][7] = Wbook.Worksheets[WorksheetName].Columns[j].Cells[i].Style.Font.Underline; DataTable1.Rows[Count][8] = Wbook.Worksheets[WorksheetName].Columns[j].Cells[i].Style.Font.Strikeout; DataTable1.Rows[Count][9] = Wbook.Worksheets[WorksheetName].Columns[j].Cells[i].Style.Font.Subscript; DataTable1.Rows[Count][10] = Wbook.Worksheets["FontAndFormat"].Rows[i].Cells[j].Style.Font.Superscript; DataTable1.Rows[Count][11] = Wbook.Worksheets["FontAndFormat"].Rows[i].Cells[j].Style.Rotation; DataTable1.Rows[Count][12] = Wbook.Worksheets["FontAndFormat"].Rows[i].Cells[j].Style.StringFormat; DataTable1.Rows[Count][13] = Wbook.Worksheets["FontAndFormat"].Rows[i].Cells[j].Style.HorizontalAlignment; DataTable1.Rows[Count][14] = Wbook.Worksheets["FontAndFormat"].Rows[i].Cells[j].Style.VerticalAlignment; Count++; } } dataGridView1.DataSource = DataTable1; } } }