예제 #1
0
        /// <summary>
        /// Экспорт в ListView
        /// </summary>
        /// <param name="lv"></param>
        /// <param name="name"></param>
        public static void MakeExcelFromLV(ListView lv, string name)
        {
            int refreshRate = lv.Items.Count / 100;

            WaitForm wf = new WaitForm();

            try {
                string path = getExportFolderPath();
                if (path == "")
                {
                    return;
                }

                path = Helper.DuplicateName(Path.Combine(path, name + " " + DateTime.Now.ToShortDateString() + EXTENTION));

                wf.Flush(); wf.MaxValue = 100; wf.Show(); wf.Style = ProgressBarStyle.Blocks;

                StreamWriter sw = new StreamWriter(new FileStream(path, FileMode.Create), Encoding.GetEncoding(TARG_ENCODING));

                int cols = lv.Columns.Count;//для обеспечения быстроты заполнения

                /// Заполнение названиями когонок
                string row = "";
                for (int h = 0; h < lv.Columns.Count; h++)
                {
                    row += String.Format("\"{0}\"{1}", lv.Columns[h].Text, SEPARATOR);
                }
                sw.WriteLine(row.TrimEnd(SEPARATOR.ToCharArray()));

                for (int i = 0; i < lv.Items.Count; i++)
                {
                    row = "";
                    for (int j = 0; j < cols; j++)
                    {
                        row += String.Format("\"{0}\"{1}", lv.Items[i].SubItems[j].Text, j != cols - 1 ? SEPARATOR : "");
                    }
                    sw.WriteLine(row.TrimEnd(SEPARATOR.ToCharArray()));
                    if (refreshRate != 0 && (i % refreshRate == 0 || i == lv.Items.Count))
                    {
                        Application.DoEvents();
                        if (!wf.isFull)
                        {
                            wf.Inc();
                        }
                    }
                }
                sw.Flush();
                sw.Close();

                wf.Hide();
            } catch (Exception ex) {
                wf.Hide();
                MessageBox.Show(ex.Message, "Произошла ошибка");
            }
        }
예제 #2
0
        public static void MakeExcelFromXML(XmlNode[] xmls, String repName, string[] headers)///Для плагинов сделать excel тоже наверное нужны делегаты или еще что
        {
            _repName = repName;
            _xmls    = xmls;
            string path = getExportFolderPath();

            if (path == "")
            {
                return;
            }
            path = Helper.DuplicateName(Path.Combine(path, filename()));

            WaitForm     wf = new WaitForm();
            StreamWriter sw = new StreamWriter(new FileStream(path, FileMode.Create), Encoding.GetEncoding(TARG_ENCODING));

            try {
                wf.Flush(); wf.MaxValue = 100; wf.Show(); wf.Style = ProgressBarStyle.Blocks;
                wf.MaxValue             = xmls[0].FirstChild.ChildNodes.Count;

                string row = "";

                for (int h = 0; h < headers.Length; h++)
                {
                    row += String.Format("\"{0}\"{1}", headers[h], SEPARATOR);
                }
                sw.WriteLine(row.TrimEnd(','));

                foreach (XmlNode nd in xmls[0].FirstChild.ChildNodes)
                {
                    row = "";
                    foreach (XmlNode nd2 in nd.ChildNodes)
                    {
                        row += String.Format("\"{0}\"{1}", nd2.InnerText, SEPARATOR);
                    }

                    sw.WriteLine(row.TrimEnd(SEPARATOR.ToCharArray()));
                    wf.Inc();
                }

                sw.Flush();
                sw.Close();

                wf.Hide();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Произошла ошибка");
                wf.Visible = false;
            }
        }