C#: Umwandeln
eines 2D Object Array to 2D String Array
Aufgabe:
Dieses Code Beispiel in C# zeigt wie man ein zwei-dimensionales
object[,] Array umwandelt in eine 2-Dimensionales string[,] Array.
Das Array besteht aus Reihen und Spalten, welche sich aus
dem Excel-Used-Range ergeben in Interop.Excel
Hier zeigt sich in
C#:
Links das objects[,] Array aus Zeilen und Spalten aus
Excel
Rechts das String[,] Array, welches nur strings und keine
null-Werte enthält.
Betrifft:
2
dimensionales Array in C#, Windows Forms
Umwandlungs
Code C#
Für das
objects[,] Array zu string[,] array
Excel.Range usedRange = _worksheet.UsedRange;
log_with_Date("get UsedRange", dtStart);
//*fast Excel-Read:
//< create 2D Array >
//*from excel with cell-content-object
object[,] arrObjectValues = usedRange.Value2;
int nRows = arrObjectValues.GetLength(0);
int nColumns = arrObjectValues.GetLength(1);
string[,] arrStringValues = new string[nRows, nColumns];
//</ create 2D Array >
//--< convert array object to string >--
for (int iRow = 0; iRow < nRows ; iRow++)
{
for(int iCol=0;iCol<nColumns ; iCol++)
{
//< Convert object to string >
arrStringValues[iRow, iCol] = Convert.ToString(arrObjectValues[iRow+1, iCol+1]);
//</ Convert object to string >
}
}
//--</ convert array object to string >--
|