本帖最后由 my200575974 于 2014-11-24 15:45:22 编辑

解决方案 »

  1.   

    同意楼上,你可以先弹出一个SaveFileDialog,选择地址之后再作为参数传给,你导出Excel的方法,导出Excel
      

  2.   

     string name = DNTRequest.GetString("fname");
    Aspose.Cells.Workbook workbook = new Workbook();
                        workbook.Worksheets[0].Cells[0, 0].Value = name;
     SaveFileDialog sfd = new SaveFileDialog();
                        if (sfd.ShowDialog() == DialogResult.OK)
                        {
                            workbook.Save(sfd.FileName);
                        }
    filename是获取选择的地址吗,
    这样报错啊
      

  3.   

     string name = DNTRequest.GetString("fname");
    Aspose.Cells.Workbook workbook = new Workbook();
                        workbook.Worksheets[0].Cells[0, 0].Value = name;
     SaveFileDialog sfd = new SaveFileDialog();
                        if (sfd.ShowDialog() == DialogResult.OK)
                        {
                            workbook.Save(sfd.FileName);
                        }
    filename是获取选择的地址吗,
    这样报错啊
    最好先百度下SaveFileDialog的用法!!
      

  4.   

     string name = DNTRequest.GetString("fname");
    Aspose.Cells.Workbook workbook = new Workbook();
                        workbook.Worksheets[0].Cells[0, 0].Value = name;
     SaveFileDialog sfd = new SaveFileDialog();
                        if (sfd.ShowDialog() == DialogResult.OK)
                        {
                            workbook.Save(sfd.FileName);
                        }
    filename是获取选择的地址吗,
    这样报错啊
    哪里报错,报什么错?
      

  5.   

     string name = DNTRequest.GetString("fname");
    Aspose.Cells.Workbook workbook = new Workbook();
                        workbook.Worksheets[0].Cells[0, 0].Value = name;
     SaveFileDialog sfd = new SaveFileDialog();
                        if (sfd.ShowDialog() == DialogResult.OK)
                        {
                            workbook.Save(sfd.FileName);
                        }
    filename是获取选择的地址吗,
    这样报错啊
    哪里报错,报什么错?
    线程错误对线程不太了解啊
    在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的 Main 函数带有 STAThreadAttribute 标记。 只有将调试器附加到该进程才会引发此异常。
      

  6.   

     string name = DNTRequest.GetString("fname");
    Aspose.Cells.Workbook workbook = new Workbook();
                        workbook.Worksheets[0].Cells[0, 0].Value = name;
     SaveFileDialog sfd = new SaveFileDialog();
                        if (sfd.ShowDialog() == DialogResult.OK)
                        {
                            workbook.Save(sfd.FileName);
                        }
    filename是获取选择的地址吗,
    这样报错啊
    哪里报错,报什么错?
    线程错误对线程不太了解啊
    在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的 Main 函数带有 STAThreadAttribute 标记。 只有将调试器附加到该进程才会引发此异常。
    http://www.cnblogs.com/Holmes-Jin/archive/2012/08/22/2650387.html
      

  7.   

    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        string file = saveFileDialog1.FileName;
                        
    }
      

  8.   

    这里有个例子http://download.csdn.net/detail/superior_yong/8040249
      

  9.   

    导出Excel文档,选择保存地址到Word文档示例
    //选择word文档保存地址
     private void btn_SelectTxt_Click(object sender, EventArgs e)
            {
                FolderBrowserDialog FBDialog=new FolderBrowserDialog();//实例化浏览文件夹对话框对象
                if (FBDialog.ShowDialog() == DialogResult.OK)//判断是否选择了文件夹
                {
                    txt_Word.Text = FBDialog.SelectedPath;//显示选择的Word存放路径
                }
            }
    //导出Excel文档
     private void btn_Read_Click(object sender, EventArgs e)
            {
                object missing = System.Reflection.Missing.Value;//获取缺少的object类型值
                string[] P_str_Names = txt_Excel.Text.Split(',');//存储所有选择的Excel文件名
                object P_obj_Name;//存储遍历到的Excel文件名
                Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();//实例化Word对象
                if (txt_Word.Text.EndsWith("\\"))//判断路径是否以\结尾
                    P_obj_WordName = txt_Word.Text + DateTime.Now.ToString("yyyyMMddhhmmss") + ".doc";//记录Word文件路径及名称
                else
                    P_obj_WordName = txt_Word.Text + "\\" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".doc";//记录Word文件路径及名称
                Microsoft.Office.Interop.Word.Table table;//声明Word表格对象
                Microsoft.Office.Interop.Word.Document document = new Microsoft.Office.Interop.Word.Document();//声明Word文档对象
                document = word.Documents.Add(ref missing, ref missing, ref missing, ref missing);//新建Word文档
                Microsoft.Office.Interop.Word.Range range ;//声明范围对象
                int P_int_Rows = 0, P_int_Columns = 0;//存储工作表中数据的行数和列数
                object P_obj_start = 0, P_obj_end = 0;//分别记录创建表格的开始和结束范围                   
                object P_obj_Range = Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseEnd;//定义要合并的范围位置
                for (int i = 0; i < P_str_Names.Length - 1; i++)//遍历所有选择的Excel文件名
                {
                    P_obj_Name = P_str_Names[i];//记录遍历到的Excel文件名
                    List<string> P_list_SheetName = CBoxBind(P_obj_Name.ToString());//获取指定Excel中的所有工作表
                    for (int j = 0; j < P_list_SheetName.Count; j++)//遍历所有工作表
                    {
                        range = document.Range(ref missing, ref missing);//获取Word范围
                        range.InsertAfter(P_obj_Name + "——" + P_list_SheetName[j] + "工作表");//插入文本
                        range.Font.Name = "宋体";//设置字体
                        range.Font.Size = 10;//设置字体大小
                        DataSet myds = CBoxShowCount(P_obj_Name.ToString(), P_list_SheetName[j]);//获取工作表中的所有数据
                        P_int_Rows = myds.Tables[0].Rows.Count;//记录工作表的行数
                        P_int_Columns = myds.Tables[0].Columns.Count;//记录工作表的列数
                        range.Collapse(ref P_obj_Range);//合并范围
                        if (P_int_Rows > 0 && P_int_Columns > 0)//判断如果工作表中有记录
                        {
                            //在指定范围处添加一个指定行数和列数的表格
                            table = range.Tables.Add(range, P_int_Rows, P_int_Columns, ref missing, ref missing);
                            for (int r = 0; r < P_int_Rows; r++)//遍历行
                            {
                                for (int c = 0; c < P_int_Columns; c++)//遍历列
                                {
                                    table.Cell(r + 1, c + 1).Range.InsertAfter(myds.Tables[0].Rows[r][c].ToString());//将遍历到的数据添加到Word表格中
                                }
                            }
                        }
                        object P_obj_Format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;//定义Word文档的保存格式
                        word.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;//设置保存时不显示对话框
                        //保存Word文档
                        document.SaveAs(ref P_obj_WordName, ref P_obj_Format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                    }
                }
                document.Close(ref missing, ref missing, ref missing);//关闭Word文档
                word.Quit(ref missing, ref missing, ref missing);//退出Word应用程序
                MessageBox.Show("已经成功将多个Excel文件的内容读取到了一个Word文档中!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }