2012-08-02 30 views
0

我试图导出数据从MS Excel表格数据表使用C#VS 2010 WinForms应用程序中的数据表。从excel导出数据到C#中的文本颜色的数据表格#

我想要根据文本forecolor从Excel中导出一些行,例如文本颜色是黑色,绿色和红色。如果文本颜色是绿色,那么我想排除该行被导出。

请让我知道如何做到这一点。

回答

0

您应该遍历Excel中的行并在导出前检查文本颜色。首先打开Excel文件。

  Microsoft.Office.Interop.Excel.Application App = new Microsoft.Office.Interop.Excel.Application(); 
      App.Visible = false; 
      App.WindowState = Excel.XlWindowState.xlMinimized; 
      App.ShowStartupDialog = false; 

      Excel.Workbook WorkBook = App.Workbooks.Open(File, 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); 

这是好事,让正在使用第一区域:

Excel.Range Area = worksheet.get_Range("A1", worksheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing)); 

迭代:

   for (int R = 1; R <= Area.Rows.Count; R++) 
       { 
       Excel.Range Row = ((Excel.Range)Area[R, "A"]); 
       if(Row.Font.Color != Excel.XlRgbColor.rgbGreen) 
       { 
        // Get data from the cells and include into a 
        // collection of items that represents data to be exported. 
       } 
       } 
+0

我无法找到枚举Excel.XlRgbColor情况下,即使我已经添加了Interop.Excel dll参考和命名空间。 – 2012-08-03 03:40:21

+0

请尝试: 使用Excel = Microsoft.Office.Interop.Excel; – Demir 2012-08-06 10:05:59

相关问题