예제 #1
0
        public void Show()
        {
            ExcelDoc excel = new ExcelDoc();

            CreateHeader(excel);

            CreateBody(excel);

            excel.Show();
        }
예제 #2
0
        private void CreateHeader(ExcelDoc excel)
        {
            int i = 1;

            foreach (DataColumn column in _dt.Columns)
            {
                excel.setValue(1, i, column.ColumnName);

                i++;
            }
        }
예제 #3
0
        private void CreateBody(ExcelDoc excel)
        {
            int i = 2;

            foreach (DataRow row in _dt.Rows)
            {
                for (int j = 0; j < row.ItemArray.Count(); j++ )
                {
                    if (row.ItemArray[j].ToString() == string.Empty)
                        continue;

                    excel.setValue(i, (j + 1), row.ItemArray[j].ToString());
                }

                i++;
            }
        }
예제 #4
0
        private void загрузитьEmailToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = @"C:\";
            openFileDialog.Filter = "Excel files (*.xls)|*.xls|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;
            openFileDialog.Multiselect = false;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                ExcelDoc excelDoc = new ExcelDoc(openFileDialog.FileName);
                int err = 0;
                int i = 2;
                try
                {

                    bool quest = true;
                    string s1;
                    clQuestion question = new clQuestion(globalData.UserID);

                    while (excelDoc.getValue("A" + i.ToString(), "A" + i.ToString()) != null)
                    {
                        s1 = excelDoc.getValue("A" + i.ToString(), "A" + i.ToString()).ToString().Replace("\"", "'");

                        if (quest)
                        {
                            question = new clQuestion(globalData.UserID);
                            question.Text = s1;
                            question.Save();

                            quest = false;
                        }
                        else
                        {
                            clAnswer answer = question.CreateAnswed();
                            answer.Right = (excelDoc.getValue("B" + i.ToString(), "B" + i.ToString()) != null);
                            answer.Text = s1;
                            answer.Save();
                        }

                        i++;

                        if (excelDoc.getValue("A" + i.ToString(), "A" + i.ToString()) == null)
                        {
                            i++;
                            quest = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка при чтении файла. Системная ошибка: " + ex.Message + " В строке " + i.ToString());
                    err++;
                }
                finally
                {
                    if (err == 0)
                    {
                        excelDoc.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("Загрузка завершена. Найдено " + err.ToString() + " ошибок.");
                        excelDoc.Show();
                    }
                }
            }
        }