/// <summary> /// 导出 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnExport_Click(object sender, EventArgs e) { fbdPath.Description = "将导出文件保存到..."; DialogResult result = fbdPath.ShowDialog(); if (result != System.Windows.Forms.DialogResult.OK) { return; } string agentname = ((AGENT_INFO)cbxAgents.SelectedItem).AI_NAME; int year = ((AGENT_YEAR)cbxYears.SelectedItem).AY_NAME; string filename = fbdPath.SelectedPath + string.Format("\\倒退表-{0}年度-{1}_{2}.xls", year, agentname, DateTime.Now.ToString("yyyyMMddHHmm")); File.WriteAllBytes(filename, TaxDemo.Properties.Resources.T3); ExcelHelper excel = new ExcelHelper(); excel.OpenFile(filename, 1); excel.SetValue(1, 2, string.Format("{0}年度{1}外派雇员境外收入境内补缴明细", year, agentname)); int i = 0; for (i = 0; i < dgvItems.Rows.Count - 1; i++) { excel.SetValue(4 + i, 1, (i + 1).ToString()); excel.SetValue(4 + i, 2, dgvItems.Rows[i].Cells[0].Value.ToString()); /* Modified by cyq 20160331 */ /* *********** Begin *********/ if (dgvItems.Rows[i].Cells[1].Value != null) { excel.SetValue(4 + i, 3, dgvItems.Rows[i].Cells[1].Value.ToString()); } else { excel.SetValue(4 + i, 3, string.Empty); } /* *********** End *********/ excel.SetValue(4 + i, 4, ((decimal)(dgvItems.Rows[i].Cells[2].Value)).ToString("N2")); excel.SetValue(4 + i, 5, ((decimal)(dgvItems.Rows[i].Cells[3].Value)).ToString("N2")); excel.SetValue(4 + i, 6, ((decimal)(dgvItems.Rows[i].Cells[4].Value)).ToString("N2")); excel.SetValue(4 + i, 7, dgvItems.Rows[i].Cells[5].Value.ToString()); excel.SetValue(4 + i, 8, ((int)(dgvItems.Rows[i].Cells[6].Value)).ToString("N2")); excel.SetValue(4 + i, 9, ((decimal)(dgvItems.Rows[i].Cells[7].Value)).ToString("N2")); } excel.SetValue(4 + i, 2, "合计:"); excel.SetValue(4 + i, 10, ((decimal)(dgvItems.Rows[i].Cells[7].Value)).ToString("N2")); excel.SetValue(6 + i, 2, lblMsg.Text); excel.SetValue(8 + i, 2, "制表:"); excel.SetValue(8 + i, 9, dateTimePicker1.Value.ToString("yyyy年MM月dd日")); excel.SetValue(9 + i, 2, "审核:"); excel.SetValue(9 + i, 9, "确认:"); excel.Close(); MessageBox.Show("导出成功", this.funName); }