private ResxData XlsToDataSet(string xlsFile) { Excel.Application app = new Excel.Application(); Excel.Workbook wb = app.Workbooks.Open(xlsFile, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); Excel.Sheets sheets = wb.Worksheets; Excel.Worksheet sheet = (Excel.Worksheet)sheets.get_Item(1); ResxData rd = new ResxData(); int row = 3; bool continueLoop = true; while (continueLoop) { string fileSrc = (sheet.Cells[row, 1] as Excel.Range).Text.ToString(); if (String.IsNullOrEmpty(fileSrc)) { break; } ResxData.ResxRow r = rd.Resx.NewResxRow(); r.FileSource = (sheet.Cells[row, 1] as Excel.Range).Text.ToString(); r.FileDestination = (sheet.Cells[row, 2] as Excel.Range).Text.ToString(); r.Key = (sheet.Cells[row, 3] as Excel.Range).Text.ToString(); r.Value = (sheet.Cells[row, 4] as Excel.Range).Text.ToString(); rd.Resx.AddResxRow(r); bool hasCulture = true; int col = 5; while (hasCulture) { string cult = (sheet.Cells[2, col] as Excel.Range).Text.ToString(); if (String.IsNullOrEmpty(cult)) { break; } ResxData.ResxLocalizedRow lr = rd.ResxLocalized.NewResxLocalizedRow(); lr.Culture = cult; lr.Key = (sheet.Cells[row, 3] as Excel.Range).Text.ToString(); lr.Value = (sheet.Cells[row, col] as Excel.Range).Text.ToString(); lr.ParentId = r.Id; lr.SetParentRow(r); rd.ResxLocalized.AddResxLocalizedRow(lr); col++; } row++; } rd.AcceptChanges(); wb.Close(false, m_objOpt, m_objOpt); app.Quit(); return(rd); }
private void ReadResx(string fileName, string projectRoot, ResxData rd, string[] cultureList, string[] excludeList, bool useFolderNamespacePrefix) { FileInfo fi = new FileInfo(fileName); string fileRelativePath = fi.FullName.Remove(0, AddBS(projectRoot).Length); string fileDestination; if (useFolderNamespacePrefix) { fileDestination = GetNamespacePrefix(AddBS(projectRoot), AddBS(fi.DirectoryName)) + fi.Name; } else { fileDestination = fi.Name; } ResXResourceReader reader = new ResXResourceReader(fileName); reader.BasePath = fi.DirectoryName; try { IDictionaryEnumerator ide = reader.GetEnumerator(); #region read foreach (DictionaryEntry de in reader) { if (de.Value is string) { string key = (string)de.Key; bool exclude = false; foreach (string e in excludeList) { if (key.EndsWith(e)) { exclude = true; break; } } if (!exclude) { string value = de.Value.ToString(); ResxData.ResxRow r = rd.Resx.NewResxRow(); r.FileSource = fileRelativePath; r.FileDestination = fileDestination; r.Key = key; value = value.Replace("\r", "\\r"); value = value.Replace("\n", "\\n"); r.Value = value; rd.Resx.AddResxRow(r); foreach (string cult in cultureList) { ResxData.ResxLocalizedRow lr = rd.ResxLocalized.NewResxLocalizedRow(); lr.Key = r.Key; lr.Value = String.Empty; lr.Culture = cult; lr.ParentId = r.Id; lr.SetParentRow(r); rd.ResxLocalized.AddResxLocalizedRow(lr); } } } } #endregion } catch (Exception ex) { MessageBox.Show("A problem occured reading " + fileName + "\n" + ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } reader.Close(); }