Ejemplo n.º 1
0
        /// <summary>
        /// 把xml里面的中文数据保存到excel
        /// </summary>
        /// <param name="path"></param>
        /// <param name="data"></param>
        private void SaveExcelFileData(string path, ArrayList data)
        {
            var xlsxConvertor = new XLSXConvertor();

            xlsxConvertor.CellWidth = 50;
            xlsxConvertor.CreateSheet("sheet1");
            xlsxConvertor.WriteCell(0, 0, "key");
            xlsxConvertor.WriteCell(0, 1, "value");
            for (int i = 0; i < data.Count; i++)
            {
                xlsxConvertor.WriteCell(i + 1, 0, data[i].ToString());
            }
            xlsxConvertor.SaveFile(path);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取excel里面的语言包数据
        /// </summary>
        /// <param name="path"></param>
        /// <param name="map"></param>
        private void GetExcelFileData(string path, Dictionary <string, string> map)
        {
            var xlsxConvertor = new XLSXConvertor();
            var stream        = File.Open(path, FileMode.Open, FileAccess.Read);
            var source        = xlsxConvertor.ReadExcel(stream);
            int rows          = source.Rows.Count;
            int columns       = source.Columns.Count;
            int keyRow        = 0;
            int keyCol        = 0;
            int valueCol      = 0;

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    string value = source.Rows[i][j].ToString();
                    if (value == "key")
                    {
                        keyRow = i;
                        keyCol = j;
                    }
                    else if (value == "value")
                    {
                        valueCol = j - keyCol;
                        break;
                    }
                }
            }

            for (int i = keyRow + 1; i < rows; i++)
            {
                string key   = source.Rows[i][keyCol].ToString();
                string value = source.Rows[i][valueCol].ToString();
                map.Add(key, value);
            }
        }