2017-03-13 11 views
0

xlsx要素を読み込み、すべての要素が印刷されるまで4行4列ずつ印刷したいが、ファイルのすべての要素を印刷するので問題がある。どのようにそれらを印刷するか4C#でxlsxファイルを読む

 // Open the Excel file. 
     Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(Path.GetFullPath(@"C:\Users\user\Documents\Book2.xlsx")); 

     // Get the first worksheet. 
     Excel.Worksheet xlWorksheet = (Excel.Worksheet)xlWorkbook.Sheets.get_Item(1); 

     // Get the range of cells which has data. 
     Excel.Range xlRange = xlWorksheet.UsedRange; 

     // Get an object array of all of the cells in the worksheet with their values. 
     object[,] valueArray = (object[,])xlRange.get_Value(
        Excel.XlRangeValueDataType.xlRangeValueDefault); 




     for (int row = 1; row <= xlWorksheet.UsedRange.Rows.Count; ++row) 
     { 
      for (int col = 1; col <= xlWorksheet.UsedRange.Columns.Count; ++col) 
      { 

       Console.WriteLine(valueArray[row, col].ToString()); 
      } 
      int y = xlWorksheet.UsedRange.Rows.Count/4; 

       for() { 

       Console.WriteLine("4 addresat e para u printuan"); 
       Console.WriteLine(" "); 
      } 
     } 

答えて

0

列/トウのコレクションの最後に到達するまでループしないでください。ループ1〜4(または0〜3)...

for (int row = 1; row <= 4; ++row) 
{ 
    for (int col = 1; col <= x4; ++col) 
    { 

     Console.WriteLine(valueArray[row, col].ToString()); 
    } 
} 
関連する問題