private void btnAdd_Click(object sender, EventArgs e) { DialogResult rsl = openFileDialog1.ShowDialog(); if (rsl == DialogResult.OK) { string file = openFileDialog1.FileName; try { string text = File.ReadAllText(file); IWorkbook workbook; IWorksheet sheet; uint lastRow; workbook = new Excel.Workbook(file); sheet = workbook.Worksheets.GetWorksheetByIndex(0); lastRow = sheet.LastRow; for (uint i = 1; i <= lastRow; i++) { IRow row = sheet.Rows.GetRow(i); AddressList element = new AddressList(); element.address = GetCellValue(row, 0).ToUpper().Replace("İ", "I"); element.name = GetCellValue(row, 1).ToUpper().Replace("İ", "I"); element.gsm = GetCellValue(row, 2).ToUpper().Replace("İ", "I"); Form1.lst.Add(element); addlist.Add(element.address); } } catch (IOException) { } } listBox1.DataSource = addlist; }
public ActionResult Save(AddLessonViewModel model, HttpPostedFileBase file) { ViewBag.Faculty = ListFaculty((int)EnumParamaterGroup.Faculty); ViewBag.Departman = ListFaculty((int)EnumParamaterGroup.Departman); ViewBag.Class = ListFaculty((int)EnumParamaterGroup.Class); if (ModelState.IsValid) { var loginUser = GetLoginUser(); using (SduEntities ent = new SduEntities()) { if (file != null) { string path = HttpContext.Server.MapPath("~/Content/docs/") + file.FileName; file.SaveAs(path); List <string> dt = new List <string>(); IWorkbook workbook; IWorksheet sheet; uint lastRow; workbook = new Excel2007.Workbook(path); sheet = workbook.Worksheets.GetWorksheetByIndex(0); lastRow = sheet.LastRow; for (uint i = 1; i <= lastRow; i++) { IRow row = sheet.Rows.GetRow(i); string studentNo = ""; studentNo = GetCellValue(row, 0); dt.Add(studentNo); } System.IO.File.Delete(path); foreach (var item in dt) { Lesson lesson = new Lesson(); lesson.FacultyID = model.FacultyID; lesson.DepartmanID = model.DepartmanID; lesson.EducatorID = loginUser.ID; lesson.LessonName = model.LessonName; lesson.ClassID = model.ClassID; lesson.LessonCode = model.LessonCode; lesson.MaxContinuity = model.MaxContinuity; lesson.StudentNo = item.ToString(); ent.Lesson.Add(lesson); ent.SaveChanges(); } } return(RedirectToAction("Index")); } } else { return(View("Index", model)); } }
internal Worksheet(Workbook wb, string name, OXWorksheet s) { #if DEBUG _cellMap = new CellMap(s); #endif _wb = wb; _s = s; _name = name; }
private static void Main() { var wb2007 = new Workbook(ExcelFilePath); Worksheet ws2007 = wb2007.GetWorksheetByName(DataElementsSheetName); GetDataElements(ws2007); ws2007 = wb2007.GetWorksheetByName(LookupsSheetName); GetLookups(ws2007); GenerateCode(); }
private static Dictionary<string, List<string>> GetSqlTypeColumnNameSuffixMappingFromExcelFile() { const string filePath = "CodeAnalysisDatabaseRules.Rules.ColumnNamingRule.xlsx"; var assembly = Assembly.GetExecutingAssembly(); var fileStream = assembly.GetManifestResourceStream(filePath); if (fileStream == null) throw new FileNotFoundException("xlsx resource not found", filePath); var wb2007 = new Workbook(fileStream); Worksheet ws2007 = wb2007.GetWorksheet(0); const string oneBlank = " "; var sqlTypeColumnNameSuffixMapping = new Dictionary<string, List<string>>(); for (var r = ws2007.CellMap.FirstRow + 1; r <= ws2007.CellMap.LastRow; r++) { var row = ws2007.GetRow(r); string sqlDataTypeName = null; string columnNameSuffixListString = null; for (var c = ws2007.CellMap.FirstCol; c <= 1; c++) { if (row.GetCell(c).Value == null || String.IsNullOrWhiteSpace(row.GetCell(c).Value.ToString())) continue; switch (c) { case 0: sqlDataTypeName = (string)row.GetCell(c).Value; break; case 1: columnNameSuffixListString = (string)row.GetCell(c).Value; break; } } if (!String.IsNullOrWhiteSpace(sqlDataTypeName) && !String.IsNullOrWhiteSpace(columnNameSuffixListString)) { var sqlDataTypeKey = sqlDataTypeName.Trim(); var regex = new Regex(@"\W+"); columnNameSuffixListString = regex.Replace(columnNameSuffixListString, oneBlank); if (columnNameSuffixListString.Trim() != String.Empty) { var columnNameSuffixList = columnNameSuffixListString.Split(new string[] { oneBlank }, StringSplitOptions. RemoveEmptyEntries); sqlTypeColumnNameSuffixMapping[sqlDataTypeKey] = columnNameSuffixList.ToList(); } } } return sqlTypeColumnNameSuffixMapping; }