Exemple #1
0
        public bool Convert()
        {
            Progress = 0;
            var xml_doc = new XmlDocument();

            xml_doc.Load(XMLPath);

            using (var xlsx_doc = new ExcelDocument())
            {
                int offset = 0;
                for (int i = 0; i < Templates.Count; i++)
                {
                    Message = "Template: " + (i + 1) + " / " + Templates.Count;

                    var template = Templates[i];

                    offset += PerformTemplate(template, xml_doc, xlsx_doc, offset);
                }

                return(xlsx_doc.Save(XLSXPath));
            }
        }
Exemple #2
0
        public void Download()
        {
            using (var Document = new ExcelDocument(XLSXPath))
            {
                Document.ColumnRow        = CRR;
                Document.ImageColumnWidth = ICWR;

                Downloading = "";
                Progress    = 0;

                int total_rows    = Document.RowCount;
                int total_columns = Document.ColumnCount;

                List <int> column_indexes = new List <int>();
                for (int i = 0; i < total_columns; i++)
                {
                    if (Columns.Contains(Document[i, 0]))
                    {
                        column_indexes.Add(i);
                    }
                }

                int total_images  = total_rows * column_indexes.Count;
                int current_count = 0;

                for (int y = 1; y < total_rows; y++)
                {
                    foreach (int x in column_indexes)
                    {
                        string url = Document[x, y];
                        if (url.Length > 0)
                        {
                            url         = Prefix + url;
                            Downloading = url;
                            ProgressChanged?.Invoke(this, EventArgs.Empty);

                            string image_path = Path.GetFullPath("image_buffer" + Path.GetExtension(url));
                            if (SaveImage(url, image_path))
                            {
                                Document.AddImage(x, y, image_path);
                                Document[x, y] = "";
                            }
                        }

                        current_count++;
                        int progress = current_count * 100 / total_images;
                        if (progress > Progress)
                        {
                            Progress = progress;
                            ProgressChanged?.Invoke(this, EventArgs.Empty);
                        }

                        var event_args = new CancelEventArgs();
                        Cancel?.Invoke(this, event_args);
                        if (event_args.Cancel)
                        {
                            Document.Save();
                            return;
                        }
                    }
                }

                Document.Save();
            }
        }