影子博客

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

private void btnQuery_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
btnQuery.Enabled = false;
label8.Visible = true;
}
Thread myThread;
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
myThread = Thread.CurrentThread;
DateTime dt1 = dateTimePicker1.Value;
DateTime dt2 = dateTimePicker2.Value;
string haocaiType = txtMaterialType.Text;
string xitong = txtSystem.Text;
string dep = txtDep.Text;
string chejian = txtChejian.Text;
string gongduan = txtReceptionGongDuan.Text;
DataTable dt = lr.get_pr_proapplyheadMaterialSUM(dt1, dt2, haocaiType, xitong, dep, chejian, gongduan);
backgroundWorker1.ReportProgress(100, dt);
}

    private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        try
        {
            DataTable dtPays = e.UserState as DataTable;

            Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook();
            workbook.Open(Application.StartupPath + @"\Templates\耗材领用汇总表.xlt");
            Aspose.Cells.Worksheet sheet = workbook.Worksheets[0];//第一个工作表

            sheet.Cells.ImportDataTable(dtPays, false, "A3");
            sheet.Cells.DeleteRows(dtPays.Rows.Count, 5);
            fpSpread1.Sheets[0].OperationMode = FarPoint.Win.Spread.OperationMode.ReadOnly;

            MemoryStream ms = workbook.SaveToStream();
            ms.Seek(0, SeekOrigin.Begin);
            fpSpread1.OpenExcel(ms);
            ms.Close();
            fpSpread1.Sheets[0].RowCount = dtPays.Rows.Count + 4;
            fpSpread1.Sheets[0].ColumnCount = 6;

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

    private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        btnQuery.Enabled = true;
        label8.Visible = false;
    }
posted on 2016-05-10 17:28  影子博客  阅读(201)  评论(0编辑  收藏  举报