Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在c#wpf中将数据导出到文件时如何显示进度条_C#_Wpf_Progress Bar_Data Export - Fatal编程技术网

在c#wpf中将数据导出到文件时如何显示进度条

在c#wpf中将数据导出到文件时如何显示进度条,c#,wpf,progress-bar,data-export,C#,Wpf,Progress Bar,Data Export,**我已经完成了将数据从数据库导出到文件的部分,但有时我发现等待此操作完成需要很长时间。因此我想在程序中添加进度条,但我的问题是: 我不知道xx.xls文件有多大 我不知道如何获得已导出文件大小的阶段 所以我不知道如何计算进度条的百分比。我应该怎么做才能获得我需要的所有信息,或者有其他解决方案吗? 非常感谢这是我的出口数据代码:** SaveFileDialog savefiledialog = new SaveFileDialog(); savefiledial

**我已经完成了将数据从数据库导出到文件的部分,但有时我发现等待此操作完成需要很长时间。因此我想在程序中添加进度条,但我的问题是:

  • 我不知道xx.xls文件有多大

  • 我不知道如何获得已导出文件大小的阶段

  • 所以我不知道如何计算进度条的百分比。我应该怎么做才能获得我需要的所有信息,或者有其他解决方案吗? 非常感谢这是我的出口数据代码:**

    SaveFileDialog savefiledialog = new SaveFileDialog();
                    savefiledialog.FileName = @"data.xlsx";
    
                    if (!(bool)savefiledialog.ShowDialog())
                        return;
    
    
    
                    DbHelper dh = new DbHelper("data.mdb");
                    ApplicationClass excel = new ApplicationClass();
    
    
                    Workbooks workbooks = excel.Workbooks;
                    Workbook workbook = workbooks.Add();
    
    
                    Worksheet sheet1 = (Worksheet)excel.ActiveSheet;
    
                    ArrayList itemList = dh.setTable("Item").where("1=1").select();
                    sheet1.Cells[1, "A"] = "col1";
                    sheet1.Cells[1, "B"] = "col2";
                    sheet1.Cells[1, "C"] = "col3";
    
    
    
                    int i = 2;
                    foreach (Item item in itemList)
                    {
                        sheet1.Cells[i, "A"] = item.Website;
                        sheet1.Cells[i, "B"] = item.Shop_id;
                        sheet1.Cells[i, "C"] = item.Title;
                        i++;
                    }
    
    
                    sheet1.Range["A1"].AutoFormat(Microsoft.Office.Interop.Excel.XlRangeAutoFormat.xlRangeAutoFormatClassic1);
    
    
                    string fileName = string.Format(savefiledialog.FileName, Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));
    
                    // Save this data as a file
                    System.Action<string, string, string, string, string, string, string, string, string, string> action = sheet1.SaveAs;
                    BackgroundWorker b = new BackgroundWorker();
                    sheet1.SaveAs(fileName);
    
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
    
                    Marshal.FinalReleaseComObject(sheet1);
    
                    workbook.Close(Type.Missing, Type.Missing, Type.Missing);
                    Marshal.FinalReleaseComObject(workbooks);
    
                    excel.Quit();
    
    SaveFileDialog SaveFileDialog=新建SaveFileDialog();
    savefiledialog.FileName=@“data.xlsx”;
    如果(!(bool)savefiledialog.ShowDialog())
    返回;
    DbHelper dh=newdbhelper(“data.mdb”);
    ApplicationClass excel=新的ApplicationClass();
    工作簿Workbooks=excel.Workbooks;
    工作簿=工作簿。添加();
    工作表sheet1=(工作表)excel.ActiveSheet;
    ArrayList itemList=dh.setTable(“项”)。其中(“1=1”).select();
    表1.单元格[1,“A”]=“col1”;
    表1.单元格[1,“B”]=“col2”;
    表1.单元格[1,“C”]=“col3”;
    int i=2;
    foreach(项目列表中的项目)
    {
    表1.单元格[i,“A”]=项目.网站;
    表1.单元格[i,“B”]=项目.车间id;
    表1.单元格[i,“C”]=项目名称;
    i++;
    }
    sheet1.Range[“A1”].AutoFormat(Microsoft.Office.Interop.Excel.XlRangeAutoFormat.xlRangeAutoFormatClassC1);
    string fileName=string.Format(savefiledialog.fileName,Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));
    //将此数据另存为文件
    System.Action Action=sheet1.SaveAs;
    BackgroundWorker b=新的BackgroundWorker();
    sheet1.SaveAs(文件名);
    GC.Collect();
    GC.WaitForPendingFinalizers();
    元帅最终选举对象(第1张);
    工作簿.Close(Type.Missing,Type.Missing,Type.Missing);
    最终电气对象(工作手册);
    excel.Quit();
    
    您可以使用表行计数,也可以显示一个不确定的状态,表示这需要几分钟的时间。你试过批量复制吗?这将使您的导出速度更快