当前位置: 首页>>代码示例>>C#>>正文


C# Worksheet.SaveAs方法代码示例

本文整理汇总了C#中Microsoft.Office.Interop.Excel.Worksheet.SaveAs方法的典型用法代码示例。如果您正苦于以下问题:C# Worksheet.SaveAs方法的具体用法?C# Worksheet.SaveAs怎么用?C# Worksheet.SaveAs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Office.Interop.Excel.Worksheet的用法示例。


在下文中一共展示了Worksheet.SaveAs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnExport_Click


//.........这里部分代码省略.........
                            {
                                //paramContent[rowIndex, paramOneColumnIndex + 2] = p3;
                                mySheet1.Cells[rowIndex + 3, paramOneColumnIndex + testInfoColumnCount + 3] = p3;
                            }
                            double p4;
                            if (double.TryParse(action2[ParamList[j].Index].Attribute("avg").Value, out p4))
                            {
                                //paramContent[rowIndex, paramOneColumnIndex + 3] = p4;
                                mySheet1.Cells[rowIndex + 3, paramOneColumnIndex + testInfoColumnCount + 4] = p4;
                            }

                        }
                    }

                    //写进度条
                    value += 1;
                    Dispatcher.Invoke(updatePbDelegate,
                        System.Windows.Threading.DispatcherPriority.Background,
                        new object[] { ProgressBar.ValueProperty, value });
                }
                //写入测试信息
                Range range1 = mySheet1.get_Range(mySheet1.Cells[3, 1], mySheet1.Cells[rowCount, testInfoColumnCount]);
                range1.Value2 = content;
                //写入参数信息
                //Range range2 = mySheet1.get_Range(mySheet1.Cells[3, testInfoColumnCount + 1], mySheet1.Cells[rowCount, testInfoColumnCount + paramCount]);
                //range2.Value2 = paramContent;

                //if (IsExportParams)
                //{
                //    rowCount = TestInfoList.Count + (ParamList.Count + 1) * TestInfoList.Count + 1;//信息行数+信息行数×参数行数+第一行列头信息
                //    paramCount = ParamList.Count + 1;//参数行数加1行参数名
                //}
                //else {
                //    rowCount = TestInfoList.Count + 1;
                //}

                //string[,] content = new string[rowCount, 13];

                //XDocument xdoc;
                //Model.TB_Dict actionModel;
                //BLL.TB_Dict dictBLL = new BLL.TB_Dict();
                //for (int i = 0; i < TestInfoList.Count; i++) {
                //    int rowIndex = i + i * paramCount;
                //    Model.TestInfoModel model = TestInfoList[i];

                //    content[rowIndex, 0] = model.Ath_Name;//姓名
                //    content[rowIndex, 1] = model.TestDate.ToString("yyyy-MM-dd HH:mm");//测试日期
                //    content[rowIndex, 2] = model.DJoint;//测试关节
                //    content[rowIndex, 3] = model.DJointSide;//测试侧
                //    content[rowIndex, 4] = model.DPlane;//运动方式
                //    content[rowIndex, 5] = model.DTestMode;//测试模式
                //    content[rowIndex, 6] = model.MotionRange;//运动范围
                //    content[rowIndex, 7] = model.Speed;//测试速度
                //    content[rowIndex, 8] = model.Break;//休息时间
                //    content[rowIndex, 9] = model.NOOfSets;//测试组数
                //    content[rowIndex, 10] = model.NOOfRepetitions;//重复次数
                //    content[rowIndex, 11] = model.DInsuredSide;//受伤测
                //    content[rowIndex, 12] = model.DGravitycomp;//重力补偿
                //    if (IsExportParams) {
                //        //写入参数信息
                //        actionModel = dictBLL.GetModel(model.Joint, model.Plane, model.Test_Mode);
                //        content[rowIndex + 1, 0] = "所选测试顺序";
                //        content[rowIndex + 1, 1] = "参数";
                //        content[rowIndex + 1, 2] = actionModel.actionone + "(极值)";
                //        content[rowIndex + 1, 3] = actionModel.actionone + "(平均值)";
                //        content[rowIndex + 1, 4] = actionModel.actiontwo + "(极值)";
                //        content[rowIndex + 1, 5] = actionModel.actiontwo + "(平均值)";
                //        string xmlPath = Model.AppPath.XmlDataDirPath + model.DataFileName;
                //        xdoc = XDocument.Load(xmlPath);
                //        List<XElement> action1 = xdoc.Descendants("action1").Elements<XElement>().ToList<XElement>();
                //        List<XElement> action2 = xdoc.Descendants("action2").Elements<XElement>().ToList<XElement>();
                //        for (int j = 0; j < ParamList.Count; j++)
                //        {
                //            content[rowIndex + 1 + j + 1, 0] = "测试" + (i + 1);
                //            content[rowIndex + 1 + j + 1, 1] = ParamList[j].ParamName;
                //            content[rowIndex + 1 + j + 1, 2] = action1[ParamList[j].Index].Attribute("max").Value;
                //            content[rowIndex + 1 + j + 1, 3] = action1[ParamList[j].Index].Attribute("avg").Value;
                //            content[rowIndex + 1 + j + 1, 4] = action2[ParamList[j].Index].Attribute("max").Value;
                //            content[rowIndex + 1 + j + 1, 5] = action2[ParamList[j].Index].Attribute("avg").Value;
                //        }
                //    }

                //    //写进度条
                //    value += 1;
                //    Dispatcher.Invoke(updatePbDelegate,
                //        System.Windows.Threading.DispatcherPriority.Background,
                //        new object[] { ProgressBar.ValueProperty, value });
                //}
                //Range range = mySheet1.get_Range(mySheet1.Cells[2, 1], mySheet1.Cells[rowCount, 13]);
                //range.Value2 = content;
                mySheet1.SaveAs(choosePath, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                myWorkBooks.Close();
                excelApp.Quit();
                MessageBox.Show("导出成功!", "系统信息");
                System.Windows.Window.GetWindow(this).Close();
            }
            catch (Exception ee) {
                MessageBox.Show("导出出错!\r\n错误信息为:" + ee.Message, "系统错误");
            }
        }
开发者ID:dewade2003,项目名称:DSJL,代码行数:101,代码来源:ExportProgressPage.xaml.cs

示例2: Export

        public void Export(List<List<XElement>> datalist,string savePath)
        {
            try
            {
                excelApp = new ApplicationClass();
                Workbooks myWorkBooks = excelApp.Workbooks;
                myWorkBooks.Open(templatePath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                Sheets sheets = excelApp.Sheets;
                mySheet1 = (Worksheet)sheets[1];
                mySheet1.Activate();

                int rowCount = 1 + 2; ;//总行数

                //写入参数信息
                int paramCount = 0;//参数行数
                List<DSJL.Model.Parameter> paramList = DSJL.Model.Parameter.GetAllParams();
                paramCount = paramList.Count * 4;
                for (int i = 0; i < paramList.Count; i++)
                {
                    Model.Parameter p = paramList[i];

                    Range r = mySheet1.get_Range(mySheet1.Cells[1, testInfoColumnCount + i * 4 + 1], mySheet1.Cells[1, testInfoColumnCount + i * 4 + 4]);
                    r.Merge();
                    r.Value = p.ParamName;
                    r.Font.Bold = true;
                    r.HorizontalAlignment = XlHAlign.xlHAlignCenter;
                    r.VerticalAlignment = XlHAlign.xlHAlignCenter;

                    Range r1 = mySheet1.get_Range(mySheet1.Cells[2, testInfoColumnCount + i * 4 + 1], mySheet1.Cells[2, testInfoColumnCount + i * 4 + 4]);
                    r1.Value2 = paramContents;
                    r1.Font.Bold = true;

                    r1.EntireColumn.AutoFit();
                }

                //写入测试信息
                string[,] content = new string[rowCount, testInfoColumnCount + paramCount];
                //double?[,] paramContent = new double?[rowCount, paramCount];

                BLL.TB_Dict dictBLL = new BLL.TB_Dict();

                int rowIndex = 0;

                //content[rowIndex, 0] ="";//测试顺序
                //content[rowIndex, 1] = model.Ath_Name;//姓名
                //content[rowIndex, 2] = model.TestDate.ToString("yyyy-MM-dd HH:mm");//测试日期
                //content[rowIndex, 3] = model.DJoint;//测试关节
                //content[rowIndex, 4] = model.DJointSide;//测试侧
                //content[rowIndex, 5] = model.DPlane;//运动方式
                //content[rowIndex, 6] = model.DTestMode;//测试模式
                //content[rowIndex, 7] = model.MotionRange;//运动范围
                //content[rowIndex, 8] = model.Speed;//测试速度
                //content[rowIndex, 9] = model.Break;//休息时间
                //content[rowIndex, 10] = model.NOOfSets;//测试组数
                //content[rowIndex, 11] = model.NOOfRepetitions;//重复次数
                //content[rowIndex, 12] = model.DInsuredSide;//受伤测
                //content[rowIndex, 13] = model.DGravitycomp;//重力补偿

                List<XElement> action1 = datalist[0];
                List<XElement> action2 = datalist[1];
                for (int j = 0; j < paramList.Count; j++)
                {
                    int paramOneColumnIndex = j * 4;
                    double p1;
                    if (double.TryParse(action1[paramList[j].Index].Attribute("max").Value, out p1))
                    {
                        //paramContent[rowIndex, paramOneColumnIndex] = p1;
                        mySheet1.Cells[rowIndex + 3, paramOneColumnIndex + testInfoColumnCount + 1] = p1;
                    }
                    double p2;
                    if (double.TryParse(action1[paramList[j].Index].Attribute("avg").Value, out p2))
                    {
                        //paramContent[rowIndex, paramOneColumnIndex + 1] = p2;
                        mySheet1.Cells[rowIndex + 3, paramOneColumnIndex + testInfoColumnCount + 2] = p2;
                    }
                    double p3;
                    if (double.TryParse(action2[paramList[j].Index].Attribute("max").Value, out p3))
                    {
                        //paramContent[rowIndex, paramOneColumnIndex + 2] = p3;
                        mySheet1.Cells[rowIndex + 3, paramOneColumnIndex + testInfoColumnCount + 3] = p3;
                    }
                    double p4;
                    if (double.TryParse(action2[paramList[j].Index].Attribute("avg").Value, out p4))
                    {
                        //paramContent[rowIndex, paramOneColumnIndex + 3] = p4;
                        mySheet1.Cells[rowIndex + 3, paramOneColumnIndex + testInfoColumnCount + 4] = p4;
                    }

                }

                //写入测试信息
                Range range1 = mySheet1.get_Range(mySheet1.Cells[3, 1], mySheet1.Cells[rowCount, testInfoColumnCount]);
                range1.Value2 = content;

                mySheet1.SaveAs(savePath, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                myWorkBooks.Close();
                excelApp.Quit();

            }
            catch (Exception ee)
//.........这里部分代码省略.........
开发者ID:dewade2003,项目名称:DSJL,代码行数:101,代码来源:ExportData.cs


注:本文中的Microsoft.Office.Interop.Excel.Worksheet.SaveAs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。