Пример #1
0
        private void AddData(ResourceDataGroupBase dataGroup, IXLWorksheet worksheet, int rowIndex, IEnumerable <CultureInfo> cultures)
        {
            worksheet.Cell(rowIndex, 1).Value = dataGroup.FileGroup.ID;
            worksheet.Cell(rowIndex, 2).Value = dataGroup.Name;

            int c = 3;

            foreach (var culture in cultures)
            {
                var cell = worksheet.Cell(rowIndex, c++);
                if (dataGroup.ResxData.ContainsKey(culture))
                {
                    cell.Value = dataGroup.ResxData[culture].Value;
                    if (ExportComments)
                    {
                        worksheet.Cell(rowIndex, c++).Value = dataGroup.ResxData[culture].Comment;
                    }
                }
                else
                {
                    cell.Value = "";
                    if (ExportComments)
                    {
                        worksheet.Cell(rowIndex, c++).Value = "";
                    }
                }
                cell.DataType = XLCellValues.Text; // need to set datatype after value is assigned, otherwise the datatype is parsed
            }
        }
Пример #2
0
        public int Import(string filename)
        {
            int count = 0;

            XmlDocument xml = new XmlDocument();

            xml.Load(filename);

            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xml.NameTable);

            namespaceManager.AddNamespace("", urnschemasmicrosoftcomofficespreadsheet);
            namespaceManager.AddNamespace("o", "urn:schemas-microsoft-com:office:office");
            namespaceManager.AddNamespace("x", urnschemasmicrosoftcomofficeexcel);
            namespaceManager.AddNamespace("ss", urnschemasmicrosoftcomofficespreadsheet);
            namespaceManager.AddNamespace("html", "http://www.w3.org/TR/REC-html40");

            List <VSCulture> cultures = new List <VSCulture>();

            XmlNodeList worksheets = xml.SelectNodes("/ss:Workbook/ss:Worksheet", namespaceManager);

            foreach (XmlNode worksheet in worksheets)
            {
                string projectName = worksheet.SelectSingleNode("@ss:Name", namespaceManager).Value;
                if (!Solution.Projects.ContainsKey(projectName))
                {
                    throw new ProjectUnknownException(projectName);
                }

                VSProject project = Solution.Projects[projectName];

                XmlNodeList nodes = worksheet.SelectNodes("ss:Table/ss:Row", namespaceManager);
                foreach (XmlNode rowNode in nodes)
                {
                    if (rowNode == rowNode.ParentNode.SelectSingleNode("ss:Row", namespaceManager))
                    {
                        XmlNodeList cellNodes = rowNode.SelectNodes("ss:Cell", namespaceManager);
                        for (int i = 2; i < cellNodes.Count; i++)
                        {
                            cultures.Add(new VSCulture(CultureInfo.GetCultureInfo(cellNodes[i].FirstChild.InnerText)));
                        }
                    }
                    else
                    {
                        string key = rowNode.ChildNodes[1].FirstChild.InnerText;
                        string id  = rowNode.FirstChild.FirstChild.InnerText;

                        ResourceDataGroupBase dataGroup = null;
                        if (!project.ResxGroups[id].AllData.ContainsKey(key))
                        {
                            dataGroup = project.ResxGroups[id].CreateDataGroup(key);
                            project.ResxGroups[id].AllData.Add(key, dataGroup);
                        }
                        else
                        {
                            dataGroup = project.ResxGroups[id].AllData[key];
                        }

                        for (int i = 0; i < cultures.Count; i++)
                        {
                            XmlNode valueNode = rowNode.SelectSingleNode("ss:Cell[@ss:Index = '" + (i + 3) + "']/ss:Data", namespaceManager);
                            if (valueNode == null)
                            {
                                valueNode = rowNode.SelectSingleNode("ss:Cell[count(@ss:Index) = 0][" + (i + 3) + "]/ss:Data", namespaceManager);
                            }

                            if (valueNode != null)
                            {
                                if (!dataGroup.ResxData.ContainsKey(cultures[i].Culture))
                                {
                                    project.ResxGroups[id].SetResourceData(key, valueNode.InnerText, cultures[i].Culture);
                                }
                                else
                                {
                                    dataGroup.ResxData[cultures[i].Culture].Value = valueNode.InnerText;
                                }

                                count++;
                            }
                        }
                    }
                }
            }

            return(count);
        }
Пример #3
0
        public int Import(string filePath)
        {
            int count = 0;

            using (var workbook = new XLWorkbook(filePath, XLEventTracking.Disabled))
            {
                foreach (var worksheet in workbook.Worksheets)
                {
                    string projectName = getProjectName(worksheet);
                    if (!Solution.Projects.ContainsKey(projectName))
                    {
                        throw new ProjectUnknownException(projectName);
                    }

                    var project      = Solution.Projects[projectName];
                    var translations = TranslationRow.LoadRows(worksheet);

                    foreach (var t in translations)
                    {
                        ResourceDataGroupBase dataGroup = null;
                        if (!project.ResxGroups[t.ID].AllData.ContainsKey(t.Key))
                        {
                            dataGroup = project.ResxGroups[t.ID].CreateDataGroup(t.Key);
                            project.ResxGroups[t.ID].AllData.Add(t.Key, dataGroup);
                        }
                        else
                        {
                            dataGroup = project.ResxGroups[t.ID].AllData[t.Key];
                        }

                        foreach (var te in t.Translations)
                        {
                            if (!dataGroup.ResxData.ContainsKey(te.Key))
                            {
                                project.ResxGroups[t.ID].SetResourceData(t.Key, te.Value, te.Key);
                                count++;
                            }
                            else if (dataGroup.ResxData[te.Key].Value != te.Value)
                            {
                                dataGroup.ResxData[te.Key].Value = te.Value;
                                count++;
                            }
                        }
                        foreach (var te in t.Comments)
                        {
                            if (!dataGroup.ResxData.ContainsKey(te.Key))
                            {
                                project.ResxGroups[t.ID].SetResourceDataComment(t.Key, te.Value, te.Key);
                                count++;
                            }
                            else if (dataGroup.ResxData[te.Key].Comment != te.Value)
                            {
                                dataGroup.ResxData[te.Key].Comment = te.Value;
                                count++;
                            }
                        }
                    }
                }
            }
            return(count);
        }