コード例 #1
0
        /// <summary>
        /// 插入数据到工作表
        /// </summary>
        /// <param name="excelUtil">源工作表文件</param>
        /// <param name="sheetIndex">工作表索引</param>
        /// <param name="startCell">开始单元</param>
        /// <param name="cb">数据源</param>
        private void AddDataToSheet(ExcelUtil excelUtil, int sheetIndex, string startCell, List<IModelObject> cb)
        {
            int temp = 0;

            foreach (ComboboxDataInfo item in cb)
            {
                temp++;
                excelUtil.AddValueToCell(sheetIndex, temp, 1, item.DisplayMember);
                excelUtil.AddValueToCell(sheetIndex, temp, 2, item.ValueMember);
            }
        }
コード例 #2
0
        private void AddDataToSheet(ExcelUtil excelUtil, int sheetIndex, string startCell, List<IModelObject> cb)
        {
            int temp = 0;
            //  StringBuilder dataBuilder = new StringBuilder();
            // string data = "";

            foreach (ComboboxDataInfo item in cb)
            {
                temp++;
                excelUtil.AddValueToCell(sheetIndex, temp, 1, item.DisplayMember);
                excelUtil.AddValueToCell(sheetIndex, temp, 2, item.ValueMember);
                // dataBuilder.Append(item.DisplayMember).Append(",");
            }
            //  Microsoft.Office.Interop.Excel.Range rang = excelUtil.GetRange(startCell, startCell).get_Resize(10000, 1);
            //  data = dataBuilder.ToString();
            //  excelUtil.AddValidation(rang, data.Substring(0, data.Length - 1));
        }
コード例 #3
0
        private void ExportChangeClassTemplate(string xlsSavePath)
        {
            ExcelUtil excelUtil = null;
            try
            {

                excelUtil = new ExcelUtil();

                excelUtil.Open(Application.StartupPath + "/ExcelTemplate/studentChangeClass.xls");
                bgWorkerGradeUpTemp.ReportProgress(10);
                //excelUtil.AddValueToCell(5,1,"simon");

                bgWorkerGradeUpTemp.ReportProgress(30);

                List<Model.IModel.IModelObject> classList = _IGeneralBL.GetMasterDataInformations(DefineConstantValue.MasterType.UserClass);

                AddDataToStuSheet(excelUtil, 3, classList);

                int startRow = 3;

                if (this._ListQueryStuInfo != null)
                {
                    foreach (CardUserMaster_cus_Info item in this._ListQueryStuInfo)
                    {
                        excelUtil.AddValueToCell(startRow, (Int32)ColName.cus_cRecordID, item.cus_cRecordID.ToString());

                        excelUtil.AddValueToCell(startRow, (Int32)ColName.cus_cChaName, item.cus_cChaName);

                        excelUtil.AddValueToCell(startRow, (Int32)ColName.cus_cStudentID, item.cus_cStudentID);

                        excelUtil.AddValueToCell(startRow, (Int32)ColName.cus_cClassName, item.ClassName);

                        startRow++;
                    }
                }

                bgWorkerGradeUpTemp.ReportProgress(90);
                excelUtil.SaveCopyAs(xlsSavePath);
                bgWorkerGradeUpTemp.ReportProgress(100);
                ShowInformationMessage("导出成功。");

            }
            catch (Exception ex)
            {
                ShowInformationMessage("导出错误,请联系管理员。错误原因:" + ex.Message);

                if (excelUtil != null)
                {
                    excelUtil.Close();
                }

            }
            finally
            {
                //add by justinleung 2011/09/06
                if (excelUtil != null)
                {
                    excelUtil.Close();
                }
                //this.Close();
            }
        }