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


C# FarPoint.SaveExcel方法代码示例

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


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

示例1: AddData

        /// <summary>
        /// 加载数据同时保存数据到指定位置
        /// </summary>
        /// <param name="obj"></param>
        private void AddData(FarPoint.Win.Spread.FpSpread obj)
        {
            wait = new WaitDialogForm("", "正在加载数据, 请稍候...");
            try
            {
                //打开Excel表格
                //清空工作表
                fpSpread1.Sheets.Clear();
                obj.OpenExcel(System.Windows.Forms.Application.StartupPath + "\\xls\\中压配电网分析.xls");
                PF.SpreadRemoveEmptyCells(obj);
                //this.AddCellChanged();
                //this.barEditItem2.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
                //S4_2_1.AddBarEditItems(this.barEditItem2, this.barEditItem1, this);
            }
            catch (System.Exception e)
            {
                //如果打开出错则重新生成并保存
                LoadData();
                //判断文件夹是否存在,不存在则创建
                if (!Directory.Exists(System.Windows.Forms.Application.StartupPath + "\\xls"))
                {
                    Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath + "\\xls");
                }
                //保存EXcel文件
                obj.SaveExcel(System.Windows.Forms.Application.StartupPath + "\\xls\\中压配电网分析.xls", FarPoint.Excel.ExcelSaveFlags.NoFlagsSet);
                // 定义要使用的Excel 组件接口
                // 定义Application 对象,此对象表示整个Excel 程序
                Microsoft.Office.Interop.Excel.Application excelApp = null;
                // 定义Workbook对象,此对象代表工作薄
                Microsoft.Office.Interop.Excel.Workbook workBook;
                // 定义Worksheet 对象,此对象表示Execel 中的一张工作表
                Microsoft.Office.Interop.Excel.Worksheet ws = null;
                Microsoft.Office.Interop.Excel.Range range = null;
                excelApp = new Microsoft.Office.Interop.Excel.Application();
                string filename = System.Windows.Forms.Application.StartupPath + "\\xls\\中压配电网分析.xls";
                workBook = excelApp.Workbooks.Open(filename, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                for (int i = 1; i <= workBook.Worksheets.Count; i++)
                {

                    ws = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[i];
                    //取消保护工作表
                    ws.Unprotect(Missing.Value);
                    //有数据的行数
                    int row = ws.UsedRange.Rows.Count;
                    //有数据的列数
                    int col = ws.UsedRange.Columns.Count;
                    //创建一个区域
                    range = ws.get_Range(ws.Cells[1, 1], ws.Cells[row, col]);
                    //设区域内的单元格自动换行
                    range.WrapText = true;
                    //保护工作表
                    ws.Protect(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                }
                //保存工作簿
                workBook.Save();
                //关闭工作簿
                excelApp.Workbooks.Close();
            }
            wait.Close();
        }
开发者ID:EdgarEDT,项目名称:myitoppsp,代码行数:64,代码来源:FrmMediumVoltageDistributionNetworkParsing.cs

示例2: InsertFpSpread

        public bool InsertFpSpread(FarPoint.Win.Spread.FpSpread fp, int sheetcount, TONLI.BZH.UI.DSOFramerWordControl wordcontrol)
        {
            try
            {
                string filename = System.Windows.Forms.Application.StartupPath + "\\BlogData\\Blog.xls";
                fp.SaveExcel(filename);
                if (sheetcount == 0)
                    sheetcount = fp.Sheets.Count;
                //fp.ActiveSheetIndex = 0;
                //for (int j = 9; j > 0; j++)
                //{
                //    fp.Sheets[j].Dispose();

                //}
                //fp.Sheets[0].SaveTextFile(""

                //FarPoint.Win.Spread.FpSpread ft=fp;

                //for (int i = 0; i < sheetcount; i++)
                //{
                //    FarPoint.Win.Spread.FpSpread ft = fp;
                //    for (int j = sheetcount; j > i; j--)
                //    {
                //        ft.Sheets.RemoveAt(j);
                //    }
                //    ft.SaveExcel(filename);
                //    wordcontrol.DoInsertOleObject(filename);

                //}

                //for (int j = 6; j > 1; j--)
                //{
                //    ft.Sheets.RemoveAt(j);
                //    ft.SaveExcel(filename);
                //    wordcontrol.DoInsertOleObject(filename);
                //}

                //string filename = System.Windows.Forms.Application.StartupPath + "\\BlogData\\Blog.xls";

                //string filename1 = System.Windows.Forms.Application.StartupPath + "\\BlogData\\Blog1.xls";
                //fp.SaveExcel(filename);

                //FarPoint.Win.Spread.FpSpread fs = new FarPoint.Win.Spread.FpSpread();
                //fs.Sheets[0].OpenExcel(filename, 1);
                //fs.SaveExcel(filename1);
                //wordcontrol.DoInsertOleObject(filename1);

                //FarPoint.Win.Spread.FpSpread fs = new FarPoint.Win.Spread.FpSpread();

                //for (int i = 0; i < sheetcount; i++)
                //{
                //    try
                //    {
                //        fs.Sheets.Clear();
                //        fs.Sheets.Add(fp.Sheets[i]);
                //        fs.SaveExcel(filename);

                //for (int i = 0; i < sheetcount; i++)
                //{
                //    fp.ActiveSheetIndex = i;
                //    MessageBox.Show("111");
                //    fp.SaveExcel(filename);
                //    MessageBox.Show("222");
                //    wordcontrol.DoInsertOleObject(filename);
                //    MessageBox.Show("333");
                //}
                    //}
                    //catch { }
                //}

                System.Drawing.Font font = new System.Drawing.Font("���ו", 12);

                Microsoft.Office.Interop.Excel.Application ep = new Microsoft.Office.Interop.Excel.Application();

                Microsoft.Office.Interop.Excel._Workbook wb = ep.Workbooks.Add(filename);

                Microsoft.Office.Interop.Excel.Sheets sheets = wb.Worksheets;

                for (int i = 1; i <= sheetcount; i++)
                {

                    //wordcontrol.DoInsertOleObject(filename);
                    Microsoft.Office.Interop.Excel._Worksheet ws = (Microsoft.Office.Interop.Excel._Worksheet)sheets.get_Item(i);// [System.Type.Missing];//.get.get_Item("xx");
                   // ws.UsedRange.se.UsedRange.Select();
                    //cli

                    ws.UsedRange.Copy(System.Type.Missing);

                    wordcontrol.DoPaste();
                    wordcontrol.DoInsert(" ", font, TONLI.BZH.UI.WdParagraphAlignment.Left);

                }
                Clipboard.Clear();
                ep.DisplayAlerts = false;
                ep.Quit();

                return true;
            }
            catch (Exception rc) { System.Windows.Forms.MessageBox.Show(rc.Message); return false; }
        }
开发者ID:EdgarEDT,项目名称:myitoppsp,代码行数:100,代码来源:LayoutsClass.cs


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