public void Add_File_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); // Set filter for file extension and default file extension dlg.DefaultExt = ".png"; dlg.Filter = "XLSX Files (*.xlsx)|*.xlsx|CSV Files (*.csv)|*.csv"; // Display OpenFileDialog by calling ShowDialog method Nullable <bool> result = dlg.ShowDialog(); // Get the selected file name and display in a TextBox if (result == true) { // Open document filename = dlg.FileName; //Supported spreadsheet formats for reading include: XLSX, XLS, CSV and TSV WorkBook workbook = WorkBook.Load(filename); WorkSheet sheet = workbook.DefaultWorkSheet; //Select cells easily in Excel notation and return the calculated value, date, text or formula int cellValue = sheet["A2"].IntValue; // Read from Ranges of cells elegantly. bool stop = false; int row = 0; octopusEntities1 db = new octopusEntities1(); RangeRow rowdata; while (!stop) { // check if existing prior to inserting ObjectResult <Octopus.checkForExistingQuestion_Result> number = db.checkForExistingQuestion(quizid, (string)sheet.GetCellAt(0, row).Text.Trim()); if (number.ToArray().Length == 0) { db.insertQuestionToQuiz(quizid, (string)sheet.GetCellAt(0, row).Text.Trim(), (string)sheet.GetCellAt(1, row).Text.Trim(), (string)sheet.GetCellAt(2, row).Text.Trim(), "basic"); } else { Console.WriteLine("Question already existing"); } row++; } } }
public void writeResult(int startRow, PrettyResult prettyResult, OutputTheme theme) { for (int i = 0; i < prettyResult.resultTable.GetLength(0); i++) { for (int j = 0; j < prettyResult.resultTable.GetLength(1); j++) { PrettyResultCell prettyCell = prettyResult.resultTable[i, j]; if (prettyCell != null) { workSheet.SetCellValue(startRow + i, j, prettyCell.value); workSheet.GetCellAt(startRow + i, j).Style.SetBackgroundColor(theme.getColor(prettyResult.resultTable[i, j].type)); } } } wb.SaveAs(filePath); }
internal List <List <double> > ObtenerDatosCicloNodo(int nodo, List <List <double> > listaDatosCicloNodo) { String path = @"C:\Users\di_eg\Desktop\Datos UOCT\Programaciones Centro LS.xls"; List <double> datosCicloNodo = new List <double>(); WorkBook workbook = WorkBook.Load(path); WorkSheet sheet = workbook.WorkSheets[nodo]; int ciclo = sheet.GetCellAt(63, 3).IntValue; //Ciclo int TF1 = sheet.GetCellAt(63, 4).IntValue; //Inicio F1 int TF2 = sheet.GetCellAt(63, 5).IntValue; //Inicio F2 int EV = sheet.GetCellAt(63, 7).IntValue; //Entreverde int IVTF1 = sheet.GetCellAt(63, 10).IntValue; //Inicio verde F1 int IVTF2 = sheet.GetCellAt(63, 11).IntValue; //Inicio verde F2 int TVF1 = sheet.GetCellAt(63, 13).IntValue; //Tiempo verde F1 int TVF2 = sheet.GetCellAt(63, 14).IntValue; //Tiempo verde F2 datosCicloNodo.Add(nodo); datosCicloNodo.Add(ciclo); datosCicloNodo.Add(TF1); datosCicloNodo.Add(TF2); datosCicloNodo.Add(EV); datosCicloNodo.Add(IVTF1); datosCicloNodo.Add(IVTF2); datosCicloNodo.Add(TVF1); datosCicloNodo.Add(TVF2); /*Console.Write("nodo[" + nodo + "]"); * for (int i = 0; i < datosCicloNodo.Count; i++) * { * Console.Write(datosCicloNodo[i] + " "); * } * Console.WriteLine(""); */ listaDatosCicloNodo.Add(datosCicloNodo); return(listaDatosCicloNodo); }