示例#1
0
        private void cmbExcelSheets_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtExcelFile.Text))
            {
                return;
            }
            if (!File.Exists(txtExcelFile.Text))
            {
                MessageBox.Show(
                    "Please select an excel file.",
                    "Select Resx",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            if (cmbExcelSheets.SelectedIndex != -1)
            {
                var cols = ResxExcel.GetExcelSheetColumns(txtExcelFile.Text, cmbExcelSheets.Text);
                cmbExcelKey.DataSource = cols;
                var cols2 = ResxExcel.GetExcelSheetColumns(txtExcelFile.Text, cmbExcelSheets.Text);
                cmbExcelTranslation.DataSource = cols2;
                if (Array.IndexOf(cols, "Name") != -1)
                {
                    cmbExcelKey.Text = "Name";
                }
            }
        }
示例#2
0
        private void ImportExcel(string excelFile, string resxFile, string sheetName, string sheetKeyColumn,
                                 string sheetTranslation, bool create)
        {
            var doc = new XmlDocument();

            doc.Load(resxFile);
            var dataList = ResxTranslator.ReadResxData(doc);

            var excelLanguages = ResxExcel.ReadExcelLanguage(excelFile, sheetName, sheetKeyColumn, sheetTranslation);

            foreach (var lngPair in excelLanguages)
            {
                var node = dataList.FirstOrDefault(x => ResxTranslator.GetDataKeyName(x) == lngPair.Key);
                if (node != null)
                {
                    ResxTranslator.SetDataValue(doc, node, lngPair.Value);
                }
                else
                {
                    ResxTranslator.AddLanguageNode(doc, lngPair.Key, lngPair.Value);
                }
            }
            doc.PreserveWhitespace = false;
            var writer = new XmlTextWriter(resxFile, Encoding.UTF8)
            {
                Formatting = Formatting.Indented
            };

            doc.Save(writer);
            writer.Close();
        }
示例#3
0
        private void btnOpenExcel_Click(object sender, EventArgs e)
        {
            if (!File.Exists(txtExcelFile.Text))
            {
                MessageBox.Show("Please select an excel file.", "Excel", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var excel = ResxExcel.ReadExcel(txtExcelFile.Text);

            if (excel == null)
            {
                MessageBox.Show("Failed to read excel file", "Excel", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            cmbExcelSheets.DataSource      = excel.SheetNames;
            cmbExcelKey.DataSource         = excel.SheetColumns;
            cmbExcelTranslation.DataSource = excel.SheetColumns;
            if (Array.IndexOf(excel.SheetColumns, "Name") != -1)
            {
                cmbExcelKey.SelectedValue = "Name";
            }

            btnImportExcel.Enabled = true;
        }