Beispiel #1
0
        /// <summary>
        /// 帳票プリント
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrint_Click(object sender, EventArgs e)
        {
            ExcelPrintChecks();


            // 帳票をプリントする
            if (chkRanking.Checked)
            {
                if (rdBook.Checked)
                {
                    // 移送項目3
                    using (ExcelManager xlMgr = new ExcelManager(System.IO.Path.GetFullPath(BOOK_RANKING_NAME)))
                    {
                        // データ抜き出し
                        DataTable dt        = dataGridView1.DataSource as DataTable;
                        int       row       = 6;
                        int       col       = 2;
                        int       sheetPage = 1;
                        for (int i = 0; i < dataGridView1.Table.Rows.Count; i++)
                        {
                            for (int j = 0; j < dataGridView1.Table.Columns.Count; j++)
                            {
                                xlMgr.WriteCell <string>(dataGridView1.Table.Rows[i][j].ToString(), (row + i), (col + j), sheetPage);
                            }
                        }

                        // ランキング抽出期間の書き込み
                        row = 2;
                        col = 7;
                        string str = RecordTermString();
                        xlMgr.WriteCell <string>(str, row, col, sheetPage);
                    }
                    return;
                }

                if (rdUser.Checked)
                {
                    // 移送項目4
                    using (ExcelManager xlMgr = new ExcelManager(System.IO.Path.GetFullPath(USER_RANKING_NAME)))
                    {
                        // データ抜き出し
                        DataTable dt        = dataGridView1.DataSource as DataTable;
                        int       row       = 6;
                        int       col       = 2;
                        int       sheetPage = 1;
                        for (int i = 0; i < dataGridView1.Table.Rows.Count; i++)
                        {
                            for (int j = 0; j < dataGridView1.Table.Columns.Count; j++)
                            {
                                xlMgr.WriteCell <string>(dataGridView1.Table.Rows[i][j].ToString(), row + i, col + j, sheetPage);
                            }
                        }

                        // ランキング抽出期間の書き込み
                        row = 2;
                        col = 4;
                        string str = RecordTermString();
                        xlMgr.WriteCell <string>(str, row, col, sheetPage);
                    }
                    return;
                }
            }
            // 移送項目2
            using (ExcelManager xlMgr = new ExcelManager(System.IO.Path.GetFullPath(HISTORY_NAME)))
            {
                // データ抜き出し
                DataTable dt              = dataGridView1.DataSource as DataTable;
                int       row             = 10;
                int       col             = 2;
                int       sheetPage       = 1;
                int       recordNumBegin  = 1;
                int       recordNumColumn = 1;

                for (int i = 0; i < dataGridView1.Table.Rows.Count; i++)
                {
                    xlMgr.WriteCell <int>((i + recordNumBegin), (row + i), recordNumColumn, sheetPage);
                    xlMgr.BorderWrite((row + i), recordNumColumn, sheetPage);

                    for (int j = 0; j < dataGridView1.Table.Columns.Count; j++)
                    {
                        xlMgr.WriteCell <string>(dataGridView1.Table.Rows[i][j].ToString(), (row + i), (col + j), sheetPage);
                        xlMgr.BorderWrite((row + i), (col + j), sheetPage);
                    }
                }
                row = 2;
                col = 11;
                xlMgr.WriteCell <string>(DateTime.Now.Date.ToString("yyyy-MM-dd"), row, col, sheetPage);
            }
            return;
        }