Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Старт конвертации");
            string importFilePath = @"C:\Users\iterator_pro\Desktop\allo_price.xlsx";

            ExelData exelData       = new ExelData(importFilePath);
            string   time           = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
            string   exportFilePath = @"C:\Users\iterator_pro\Desktop\allo_price.xml";
            //      string time = "2021-05-12 17:05";
            //string head = "This XML file does not appear to have any style information associated with it. The document tree is shown below.\n" +
            string head = "<?xml version = \"1.0\" encoding = \"UTF-8\" ?>\n" +
                          //    "<!DOCTYPE yml_catalog SYSTEM \"shops.dtd\" >\n" +
                          "<yml_catalog date = \"" + time + "\" >\n" +
                          "<shop>\n" +
                          "<name>" + exelData.company.name + "</name>\n" +
                          "<company>" + exelData.company.url + "</company>\n" +
                          "<currencies>\n" +
                          "<currency id = \"" + exelData.company.currenciesId +
                          "\" rate = \"" + exelData.company.currenciesRate + "\"/>\n" +
                          "</currencies>\n";

            string categoryTegs = "";

            //create categories from exel file

            string categoriesHead   = "<categories>\n";
            string categoriesFooter = "\n</categories>\n";

            foreach (var ct in exelData.categories)
            {
                categoryTegs = "<category id=\"" + ct.id + "\" parentId =\"" + ct.parentId + "\">" + ct.value + "</categotry>\n";
            }
            string categories = categoriesHead + categoryTegs + categoriesFooter;

            string offer = "";

            //create offers from exel file

            string offerHead    = "<offers>\n";
            string offerFootter = "\n</offers>\n";
            string offers       = offerHead + offer + offerFootter;

            string body   = categories + offers;
            string footer = "</shop>\n" +
                            "</yml_catalog>";

            string text = head + body + footer;

            using (FileStream fstream = new FileStream(exportFilePath, FileMode.OpenOrCreate))
            {
                // преобразуем строку в байты
                byte[] array = System.Text.Encoding.Default.GetBytes(text);
                // запись массива байтов в файл
                fstream.Write(array, 0, array.Length);
                Console.WriteLine("Текст записан в файл " + exportFilePath);
            }
        }
Esempio n. 2
0
        public void writeDataToExel(string filePathPLU, IProgress <int> progress, ExelData exelData)
        {
            //  ForWeight forWeight = new ForWeight();
            int count = 0;
            //foreach (var data in datas)
            //{
            //    count++;
            //    if (data.Column0.Equals("1"))
            //    {
            //        forWeight.plu = data.Column11;
            //        forWeight.namePlu = data.Column3;
            //        forWeight.namePLU2 = data.Column4;
            //        forWeight.articul = data.Column5;
            //        forWeight.group = Int32.Parse(data.Column2);
            //        forWeight.price = data.Column6;
            //        forWeight.expirationDate = data.Column7;
            //        forWeight.date = data.Column7;
            //        forWeight.pluType = "By Weight";
            //        forWeight.discount = "No";
            //        forWeight.freePrice = "No";
            //        forWeight.additionalText = "0";
            //        forWeight.buttonNumber = "0";
            //        forWeight.spesialProposition = "0.00";

            //        forWeights.Add(forWeight);
            //        forWeight = new ForWeight();
            //        progress.Report((count * 100) / datas.Count());
            //    }
            //}

            // Lets converts our object data to Datatable for a simplified logic.
            // Datatable is most easy way to deal with complex datatypes for easy reading and formatting.

            //DataTable table = (DataTable)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(forWeights), (typeof(DataTable)));
            //var memoryStream = new MemoryStream();

            //using (var fs = new FileStream(filePathPLU, FileMode.Create, FileAccess.Write))
            //{
            //    IWorkbook workbook = new XSSFWorkbook();
            //    ISheet excelSheet = workbook.CreateSheet("Sheet1");

            //    List<String> columns = new List<string>();
            //    IRow row = excelSheet.CreateRow(0);
            //    int columnIndex = 0;

            //foreach (System.Data.DataColumn column in table.Columns)
            //{
            //    columns.Add(column.ColumnName);
            //    row.CreateCell(columnIndex).SetCellValue(column.ColumnName);
            //    columnIndex++;
            //}

            //int rowIndex = 1;
            //foreach (DataRow dsrow in table.Rows)
            //{
            //    row = excelSheet.CreateRow(rowIndex);
            //    int cellIndex = 0;
            //    foreach (String col in columns)
            //    {
            //        row.CreateCell(cellIndex).SetCellValue(dsrow[col].ToString());
            //        cellIndex++;
            //    }

            //    rowIndex++;
            //}
            //workbook.Write(fs);
        }