public static void printDataSetToExcel(Excel.Workbook workbook, Excel.Worksheet newDataSetSheet, ListSerializableDataStruct lsds, int sheetNumber) { //Excel.Worksheet newDataSetSheet = null; //Excel.Sheets excel_sheets = workbook.Worksheets; //newDataSetSheet = excel_sheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing); //newDataSetSheet.Name = "New Data Set" + sheetNumber; for (int i = 4; i < lsds.dataTypesLabels.Count; i++) { newDataSetSheet.Cells[1, i - 3].Value2 = lsds.dataTypesLabels[i]; } for (int i = 2; i < lsds.getCount() + 2; i++) { int j = 1; SerializableDataStruct sds = lsds.getSDS(i - 2); newDataSetSheet.Cells[i, j++].Value2 = sds.wind_speed; newDataSetSheet.Cells[i, j++].Value2 = sds.cross_wind; newDataSetSheet.Cells[i, j++].Value2 = sds.head_wind; newDataSetSheet.Cells[i, j++].Value2 = sds.temp; newDataSetSheet.Cells[i, j++].Value2 = sds.wind_chill; newDataSetSheet.Cells[i, j++].Value2 = sds.rel_hum; newDataSetSheet.Cells[i, j++].Value2 = sds.heat_index; newDataSetSheet.Cells[i, j++].Value2 = sds.dew_point; newDataSetSheet.Cells[i, j++].Value2 = sds.wet_bulb; newDataSetSheet.Cells[i, j++].Value2 = sds.bar; newDataSetSheet.Cells[i, j++].Value2 = sds.alt; newDataSetSheet.Cells[i, j++].Value2 = sds.den_alt; } }
public static ListSerializableDataStruct getDataSet(Excel.Range used_range, Excel.Workbook workbook) { ListSerializableDataStruct DataSet = new ListSerializableDataStruct(); int maxRow = used_range.Rows.Count; int maxColumn = used_range.Columns.Count; List <string> config = new List <string>(); for (int row = 1; row <= maxRow; row++) { if (row == 1) { for (int column = 1; column <= maxColumn; column++) { config.Add((string)used_range[row, column].Value2); } row++; DataSet.setTypeList(config); } else { SerializableDataStruct newRecord = new SerializableDataStruct(); for (int column = 1; column <= maxColumn; column++) { object value = used_range[row, column].Value2; if (config[column - 1] == "FORMATTED DATE-TIME") { value = used_range[row, column].Value; DateTime dateTime = (DateTime)value; } else if (config[column - 1] == "DT") { double timeInSecs = (double)value; newRecord.time_seconds = timeInSecs; } else if (config[column - 1] == "MG") { string mg = (string)value; newRecord.mag_dir = mg; } else if (config[column - 1] == "TR") { string mg = (string)value; newRecord.true_dir = mg; } else if (config[column - 1] == "WS") { double ws = (double)value; newRecord.wind_speed = ws; } else if (config[column - 1] == "CW") { double cw = (double)value; newRecord.cross_wind = cw; } else if (config[column - 1] == "HW") { double hw = (double)value; newRecord.head_wind = hw; } else if (config[column - 1] == "TP") { double tp = (double)value; newRecord.temp = tp; } else if (config[column - 1] == "WC") { double wc = (double)value; newRecord.wind_chill = wc; } else if (config[column - 1] == "RH") { double rh = (double)value; newRecord.rel_hum = rh; } else if (config[column - 1] == "HI") { double hi = (double)value; newRecord.heat_index = hi; } else if (config[column - 1] == "DP") { double dp = (double)value; newRecord.dew_point = dp; } else if (config[column - 1] == "WB") { double wb = (double)value; newRecord.wet_bulb = wb; } else if (config[column - 1] == "BP") { double bp = (double)value; newRecord.bar = bp; } else if (config[column - 1] == "AL") { double al = (double)value; newRecord.alt = al; } else if (config[column - 1] == "DA") { double da = (double)value; newRecord.den_alt = da; } } DataSet.add(newRecord); } } return(DataSet); }
private void timer_Tick(object sender, EventArgs e) { liveList.add(whm.getKestrelAppData()); foreach (Excel.Worksheet sheet in workbook.Sheets) { if (sheet.Name == "Auto Collect") AutoCollectDataSheet = sheet; } AutoCollectDataSheet.Range["A1", "M100"].Clear(); for (int i = 4; i < liveList.dataTypesLabels.Count; i++) { AutoCollectDataSheet.Cells[1, i - 3].Value2 = liveList.dataTypesLabels[i]; } List<double> aves = liveList.getAverages(); for (int i = 4; i < liveList.dataTypesLabels.Count; i++) { AutoCollectDataSheet.Cells[2, i - 3].Value2 = aves[i-4]; } for (int i = 4; i < liveList.getCount() + 3; i++) { int j = 1; SerializableDataStruct sds = liveList.getSDS(i - 3); if (sds.wind_speed > 2.5 * aves[j-1] || (sds.wind_speed+1) * 2.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); else if (sds.wind_speed > 1.5 * aves[j-1] || (sds.wind_speed+1) * 1.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow); AutoCollectDataSheet.Cells[i, j++].Value2 = sds.wind_speed; if (sds.cross_wind > 2.5 * aves[j - 1] || (sds.cross_wind+1) * 2.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); else if (sds.cross_wind > 1.5 * aves[j - 1] || (sds.cross_wind+1) * 1.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow); AutoCollectDataSheet.Cells[i, j++].Value2 = sds.cross_wind; if (sds.head_wind > 2.5 * aves[j - 1] || (sds.head_wind+1) * 2.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); else if (sds.head_wind > 1.5 * aves[j - 1] || (sds.head_wind+1) * 1.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow); AutoCollectDataSheet.Cells[i, j++].Value2 = sds.head_wind; if (sds.temp > 2.5 * aves[j - 1] || sds.temp * 2.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); else if (sds.temp > 1.5 * aves[j - 1] || sds.temp * 1.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow); AutoCollectDataSheet.Cells[i, j++].Value2 = sds.temp; if (sds.wind_chill > 2.5 * aves[j - 1] || sds.wind_chill * 2.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); else if (sds.wind_chill > 1.5 * aves[j - 1] || sds.wind_chill * 1.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow); AutoCollectDataSheet.Cells[i, j++].Value2 = sds.wind_chill; if (sds.rel_hum > 2.5 * aves[j - 1] || sds.rel_hum * 2.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); else if (sds.rel_hum > 1.5 * aves[j - 1] || sds.rel_hum * 1.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow); AutoCollectDataSheet.Cells[i, j++].Value2 = sds.rel_hum; if (sds.heat_index > 2.5 * aves[j - 1] || sds.heat_index * 2.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); else if (sds.heat_index > 1.5 * aves[j - 1] || sds.heat_index * 1.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow); AutoCollectDataSheet.Cells[i, j++].Value2 = sds.heat_index; if (sds.dew_point > 2.5 * aves[j - 1] || sds.dew_point * 2.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); else if (sds.dew_point > 1.5 * aves[j - 1] || sds.dew_point * 1.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow); AutoCollectDataSheet.Cells[i, j++].Value2 = sds.dew_point; if (sds.wet_bulb > 2.5 * aves[j - 1] || sds.wet_bulb * 2.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); else if (sds.wet_bulb > 1.5 * aves[j - 1] || sds.wet_bulb * 1.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow); AutoCollectDataSheet.Cells[i, j++].Value2 = sds.wet_bulb; if (sds.bar > 2.5 * aves[j - 1] || sds.bar * 2.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); else if (sds.bar > 1.5 * aves[j - 1] || sds.bar * 1.5 < aves[j - 1]) AutoCollectDataSheet.Cells[i, j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow); AutoCollectDataSheet.Cells[i, j++].Value2 = sds.bar; AutoCollectDataSheet.Cells[i, j++].Value2 = sds.alt; AutoCollectDataSheet.Cells[i, j++].Value2 = sds.den_alt; } }