I want to export my arraylist to excel. I added my arrays for example with the name _myMAXIMUM
to my arraylist.
list.Add(_myMAXIMUM);
My array myMAXIMUM
has double values ->
- 34.43
- 234.34
- 234.5667
- 3.6 ...
So my problem is i dont understand the loop. I can not program a loop or a foreach to export all my values of my arraylist to excel. I searched for solutions but it does not work ... i am new in c# so its very hard for me. The other part of my code should be ok i think. Thank you in advance.
This is my target
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Microsoft.Office.Interop.Excel;
using System.Diagnostics;
using System.Runtime.InteropServices;
//using Microsoft.Office.Interop.Excel;
using Excel = Microsoft.Office.Interop.Excel;
System.Collections.ArrayList list = new System.Collections.ArrayList();
list.Add(_myMAXIMUM);
list.Add(_myMINIMUM);
list.Add(_mymin);
list.Add(_mymax);
list.Add(_myminID);
list.Add(_mymaxID);
list.Add(_myminSubID);
list.Add(_mymaxSubID);
int numberOfRows = 7;
int numofcolumns = 8;
Excel.Application xlApp = null;
Excel.Workbook xlWorkBook = null;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add();
Excel.Worksheet newWorksheet = null;
newWorksheet = (Excel.Worksheet)xlApp.Application.Worksheets.Add();
xlApp.ScreenUpdating = false;
Excel.Range excelRange = newWorksheet.UsedRange;
for (int row = 0; row < numberOfRows; row++)
{
for (int col = 0; col < numofcolumns; col++)
{
excelRange.Cells.set_Item(row, col,list);
}
}
xlApp.ScreenUpdating = true;
// Save it as .xls
newWorksheet.SaveAs("D:\\Datenverarbeitung", Excel.XlFileFormat.xlExcel7);
xlApp.ScreenUpdating = true;
// Clean up
xlWorkBook.Close();
xlApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
xlApp.ScreenUpdating = true;