private void button12_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.AddExtension = true;
            sfd.Filter       = "Excel File 97-2003 Worksheet (*.xls)|*.xls";
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK && sfd.FileName != "")
            {
                if (Path.GetExtension(sfd.FileName) == ".xls")
                {
                    ExcelLibrary.SpreadSheet.Worksheet worksheet = new ExcelLibrary.SpreadSheet.Worksheet("Итоговые результаты");
                    ExcelLibrary.SpreadSheet.Workbook  workbook  = new ExcelLibrary.SpreadSheet.Workbook();
                    string[] columnsName = new string[] { "№ ступени:", "H0, кДж/кг", "G, кг/с", "КПДoi", "N, МВт" };
                    for (int i = 0; i < columnsName.Length; i++)
                    {
                        worksheet.Cells[0, i] = new ExcelLibrary.SpreadSheet.Cell(columnsName[i]);
                    }
                    for (int i = 0; i <= P.Z; i++)
                    {
                        for (int k = 0; k < 5; k++)
                        {
                            worksheet.Cells[i + 1, k] = new ExcelLibrary.SpreadSheet.Cell((String)dataGridView1.Rows[i].Cells[k].Value);
                        }
                    }
                    workbook.Worksheets.Add(worksheet);
                    workbook.Save(sfd.FileName);
                }
            }
        }
Example #2
0
        private void импортВExcelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.AddExtension = true;
            sfd.Filter       = "Excel File 97-2003 Worksheet (*.xls)|*.xls";
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK && sfd.FileName != "")
            {
                if (Path.GetExtension(sfd.FileName) == ".xls")
                {
                    ExcelLibrary.SpreadSheet.Worksheet worksheet = new ExcelLibrary.SpreadSheet.Worksheet("Параметры ступеней");
                    ExcelLibrary.SpreadSheet.Workbook  workbook  = new ExcelLibrary.SpreadSheet.Workbook();
                    string[] columnsName = new string[] { "Величина", "Единица измерения", "Значение" };
                    for (int i = 0; i < columnsName.Length; i++)
                    {
                        worksheet.Cells[1, i] = new ExcelLibrary.SpreadSheet.Cell(columnsName[i]);
                    }
                    for (int i = 0; i < j; i++)
                    {
                        worksheet.Cells[i + 2, 0] = new ExcelLibrary.SpreadSheet.Cell((String)DB.Rows[i].Cells[0].Value);
                        worksheet.Cells[i + 2, 1] = new ExcelLibrary.SpreadSheet.Cell((String)DB.Rows[i].Cells[1].Value);
                        worksheet.Cells[i + 2, 2] = new ExcelLibrary.SpreadSheet.Cell((String)DB.Rows[i].Cells[2].Value);
                    }
                    worksheet.Cells.ColumnWidth[0] = 30000;

                    workbook.Worksheets.Add(worksheet);
                    workbook.Save(sfd.FileName);
                }
            }
        }
Example #3
0
        private void btnLoadXls_Click(object sender, EventArgs e)
        {
            OpenFileDialog opendlg = new OpenFileDialog();
            opendlg.Filter = "Xls Files (.xls)|*.xls";

            if (DialogResult.OK == opendlg.ShowDialog())
            {
                cmbSelezionaFoglio.Items.Clear();
                ExcelLibrary.SpreadSheet.Workbook workbook = new ExcelLibrary.SpreadSheet.Workbook();
                workbook = ExcelLibrary.SpreadSheet.Workbook.Load(opendlg.FileName);
                txtFilenameXls.Text = opendlg.FileName;
                Console.WriteLine("Sheets name in Xls: ");
                for (int i = 0; i < workbook.Worksheets.Count; i++)
                {
                    Console.WriteLine(workbook.Worksheets[i].Name);
                    cmbSelezionaFoglio.Items.Add(workbook.Worksheets[i].Name);
                }
            }
        }
Example #4
0
        /// <summary>
        /// reaction for click on menu -> file -> save
        /// </summary>
        /// <remarks>
        /// it shows a "save file dialog", and chooses the save type by the extention
        /// </remarks>
        private void menu_file_save_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.AddExtension = true;
            sfd.Filter = "text file (*.txt)|*.txt|Excel File 97-2003 Worksheet (*.xls)|*.xls";
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK && sfd.FileName != "")
            {
                if (Path.GetExtension(sfd.FileName) == ".txt")
                {
                    #region txt File

                    StreamWriter sw = new StreamWriter(sfd.FileName);
                    sw.WriteLine("date_time_type_mark_name_time");
                    sw.WriteLine("===========================");
                    foreach (Classes.Mark mark in Code.Files.MarksFile.ReadAllMarks())
                    {
                        sw.WriteLine(mark.DateTime.ToShortDateString() + '_' + mark.DateTime.ToLongTimeString() + '_' + mark.quizType.ToString() + '_'
                            + mark.mark + '_' + mark.name + "_" + mark.secendsToFinish);
                    }
                    sw.Close();

                    #endregion txt File
                }
                else if (Path.GetExtension(sfd.FileName) == ".xls")
                {
                    #region excel File

                    ExcelLibrary.SpreadSheet.Workbook workbook = new ExcelLibrary.SpreadSheet.Workbook();
                    ExcelLibrary.SpreadSheet.Worksheet worksheet = new ExcelLibrary.SpreadSheet.Worksheet("ציונים");

                    { // writes columns
                        string[] columnsName = new string[] { "שם פרטי", "שם משפחה", "תאריך", "שעה", "סוג הבוחן", "ציון", "משך הבחינה" };
                        for (int i = 0; i < columnsName.Length; i++)
                        {
                            worksheet.Cells[0, i] = new ExcelLibrary.SpreadSheet.Cell(columnsName[i]);
                        }
                    }

                    { // writes all marks
                        List<Classes.Mark> list = Code.Files.MarksFile.ReadAllMarks();
                        for (int i = 0; i < list.Count; i++)
                        {
                            Classes.Mark m = list[i];
                            Peulot_Heshbon.Classes.PersonName pn = Peulot_Heshbon.Classes.PersonName.Parse(m.name.Replace(' ', '_'));
                            worksheet.Cells[i + 1, 0] = new ExcelLibrary.SpreadSheet.Cell(pn.FirstName); // first name
                            worksheet.Cells[i + 1, 1] = new ExcelLibrary.SpreadSheet.Cell(pn.LastName); // first name
                            worksheet.Cells[i + 1, 2] = new ExcelLibrary.SpreadSheet.Cell(m.DateTime.ToShortDateString()); // date
                            worksheet.Cells[i + 1, 3] = new ExcelLibrary.SpreadSheet.Cell(m.DateTime.ToShortTimeString()); // date
                            worksheet.Cells[i + 1, 4] = new ExcelLibrary.SpreadSheet.Cell(m.quizType.ToString()); // type
                            worksheet.Cells[i + 1, 5] = new ExcelLibrary.SpreadSheet.Cell(m.mark); // mark
                            worksheet.Cells[i + 1, 6] = new ExcelLibrary.SpreadSheet.Cell(m.secendsToFinish); // duaranceTime
                        }
                    }
                    workbook.Worksheets.Add(worksheet);
                    workbook.Save(sfd.FileName);

                    #endregion excel File
                }
            }
        }
        public SESIndicationsViewModel(Window ownerWindow)
        {
            _mainWindow = ownerWindow;
            if (_mainWindow != null)
            {
                _mainWindow.Loaded += (s, e) =>
                {
                    //LoadData();
                }
            }
            ;


            GetData = new DelegateCommand(() =>
            {
                if (IsServiceAvailable == false)
                {
                    MessageBox.Show("Web-сервис АРМТЕС не доступен!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                IsBusy    = true;
                var watch = System.Diagnostics.Stopwatch.StartNew();
                var task  = Task.Factory.StartNew(Start);
                task.ContinueWith(t =>
                {
                    watch.Stop();
                    System.Diagnostics.Trace.TraceInformation("GetData -> {0} ms", watch.ElapsedMilliseconds);

                    IsBusy         = false;
                    Status         = null;
                    DetailedStatus = null;
                });
                task.ContinueWith(t =>
                {
                    MessageBox.Show(App.GetExceptionDetails(t.Exception), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                }, TaskContinuationOptions.OnlyOnFaulted);
            });

            Save = new DelegateCommand <Xceed.Wpf.DataGrid.DataGridControl>((o) =>
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();

                Xceed.Wpf.DataGrid.DataGridControl grid = o as Xceed.Wpf.DataGrid.DataGridControl;



                ExcelLibrary.SpreadSheet.Workbook workbook   = new ExcelLibrary.SpreadSheet.Workbook();
                ExcelLibrary.SpreadSheet.Worksheet worksheet = new ExcelLibrary.SpreadSheet.Worksheet("First Sheet");
                worksheet.Cells[0, 1]             = new ExcelLibrary.SpreadSheet.Cell((short)1);
                worksheet.Cells[2, 0]             = new ExcelLibrary.SpreadSheet.Cell(9999999);
                worksheet.Cells[3, 3]             = new ExcelLibrary.SpreadSheet.Cell((decimal)3.45);
                worksheet.Cells[2, 2]             = new ExcelLibrary.SpreadSheet.Cell("Text string");
                worksheet.Cells[2, 4]             = new ExcelLibrary.SpreadSheet.Cell("Second string");
                worksheet.Cells[4, 0]             = new ExcelLibrary.SpreadSheet.Cell(32764.5, "#,##0.00");
                worksheet.Cells[5, 1]             = new ExcelLibrary.SpreadSheet.Cell(DateTime.Now, @"YYYY-MM-DD");
                worksheet.Cells.ColumnWidth[0, 1] = 3000;

                string executionPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
                string fileName      = System.IO.Path.Combine(executionPath, "export.xls");

                workbook.Worksheets.Add(worksheet); workbook.Save(fileName);

                watch.Stop();
                System.Diagnostics.Trace.TraceInformation("Save -> {0} ms", watch.ElapsedMilliseconds);

                var p = new System.Diagnostics.Process
                {
                    StartInfo = new System.Diagnostics.ProcessStartInfo(fileName)
                    {
                        UseShellExecute = true
                    }
                };
                p.Start();

                /*if (grid != null)
                 *  Xceed.Wpf.DataGrid.Export.*/
            });

            Print = new DelegateCommand(() =>
            {
            }, () => true, "Печать");

            Update = new DelegateCommand(() =>
            {
            }, () => Items != null, "Обновить");
        }
Example #6
0
        private void ExcelConvertionClients(string file)
        {
            try
            {
                Excel.SpreadSheet.Workbook workbook = new Excel.SpreadSheet.Workbook();
                Excel.SpreadSheet.Worksheet worksheet = new Excel.SpreadSheet.Worksheet("Clients");
                workbook.Worksheets.Add(worksheet);

                for (int i = 0; i < 100; i++)
                    worksheet.Cells[i, 0] = new Excel.SpreadSheet.Cell("");

                worksheet.Cells[0, 0] = new Excel.SpreadSheet.Cell("[Clients de Geneviève Bonjean]");
                worksheet.Cells[0, 4] = new Excel.SpreadSheet.Cell(string.Format("Tableau réalisée le : [{0}]", DateTime.Now), Excel.SpreadSheet.CellFormat.Date);
                worksheet.Cells[0, 11] = new Excel.SpreadSheet.Cell("Créer par Arno Dupont");
                for (int i = 0; i < m_clients.Count; i++)
                {
                    int row = i + 2;
                    worksheet.Cells[row, 0] = new Excel.SpreadSheet.Cell(m_clients[i].Nom);
                    worksheet.Cells[row, 3] = new Excel.SpreadSheet.Cell(m_clients[i].Commune);
                    worksheet.Cells[row, 6] = new Excel.SpreadSheet.Cell(m_clients[i].Localité);
                    worksheet.Cells[row, 9] = new Excel.SpreadSheet.Cell(m_clients[i].TvaNum);
                    worksheet.Cells[row, 11] = new Excel.SpreadSheet.Cell(m_clients[i].InfoSuppl);
                }

                workbook.Save(file);
            }
            catch (Exception e)
            {
                new ClientListException("Erreur lors de la conversion en fichier Excel ! erreur : " + e.Message);
            }


        }
Example #7
0
        void Button4Click(object sender, EventArgs e)
        {
            var da = new DataSet();
            var dt = new DataTable();

            for (int i=0; i<dataGridView2.Columns.Count; i++) {
                dt.Columns.Add(dataGridView2.Columns[i].Name.Remove(0, 6));
            }

            foreach (DataGridViewRow row in dataGridView2.Rows) {
                DataRow dr = dt.NewRow();

                for (int j=0; j<dataGridView2.Columns.Count; j++) {
                    dr[j] = row.Cells[j].FormattedValue;
                }

                dt.Rows.Add(dr);
            }

            da.Tables.Add(dt);

            var workbook = new ExcelLibrary.SpreadSheet.Workbook();
            ExcelLibrary.DataSetHelper.CreateWorkbook("Feuille_compta.xls", da);
        }