Exporting to Excel using C# and Visual Studio 2005
-
Hi All, I have created a project that exports data to Excel. I take some samples and display it using excel. I have 4 columns: time, X, Y, Z data. The X,Y,Z data is integer data and exports perfectly. The time column doesn't work. I create the array and then I try to export it, but for some reason with double it changes all the array to the first time value .1s and if I have it as a string instead it changes all the values in the array to the final read value. Does anyone know how to display the time. I am taking a sample every 100ms so I am trying to do an elapsed timer. Please help. Below is my export to excel function:
private void button2_Click(object sender, EventArgs e) { timerTakeData.Enabled = false; radioButton10.Enabled = true; radioButton100.Enabled = true; radioButton20.Enabled = true; radioButton200.Enabled = true; radioButton50.Enabled = true; button1.Enabled = true; labelTime.Text = "0.00"; Excel.Workbooks ExcelBooks; Excel.Sheets ExcelSheets; Excel._Worksheet ExcelSheet; Excel.Range range; timerTakeData.Enabled = false; radioButton10.Enabled = true; radioButton100.Enabled = true; radioButton20.Enabled = true; radioButton200.Enabled = true; radioButton50.Enabled = true; button1.Enabled = true; labelTime.Text = "0.00"; Excel.Workbooks ExcelBooks; Excel.Sheets ExcelSheets; Excel._Worksheet ExcelSheet; Excel.Range range; try { // Instantiate Excel and start a new workbook. ExcelApp = new Excel.Application(); ExcelBooks = ExcelApp.Workbooks; ExcelBook = ExcelBooks.Add(Missing.Value); ExcelSheets = ExcelBook.Worksheets; ExcelSheet = (Excel._Worksheet)ExcelSheets.get_Item(1); ExcelSheet.Cells[1, 1] = "Time"; ExcelSheet.Cells[1, 2] = "X A/D"; ExcelSheet.Cells[1, 3] = "Y A/D"; ExcelSheet.Cells[1, 4] = "Z A/D"; ExcelSheet.get_Range("A1", "D1").Font.Bold = true; ExcelSheet.get_Range("A1", "D1").VerticalAlignment = Excel.XlVAlign.xlVAlignCenter; range = ExcelSheet.get_Range("A2", Missing.Value); range = range.get_Resi