private void ExportExcel() { IEnumerable <Object> dtSV = null; var MaKhoa = srcKhoa.EditValue.ToString(); if (MaKhoa == "admin") { dtSV = SinhVienRepository.GetAllSinhVienToExportExcel(srcKhoa.EditValue.ToString()); } else { dtSV = SinhVienRepository.GetSinhVienToExportExcel(srcKhoa.EditValue.ToString()); } DataTable dt = ConvertDataTable.LINQToDataTable(dtSV); SaveExcel.FileName = "DanhSachSV"; if (SaveExcel.ShowDialog() == DialogResult.OK) { string FolderPath = SaveExcel.FileName; using (XLWorkbook wb = new XLWorkbook()) { var ws = wb.Worksheets.Add(dt, "Temp"); wb.SaveAs(FolderPath + ".xlsx"); } XtraMessageBox.Show("Xuất Excel thành công !", "Thông báo", MessageBoxButtons.OK); } }
private void Button4_Click(object sender, EventArgs e) { DialogResult DResult = SaveExcel.ShowDialog(); if (DResult != DialogResult.Cancel && DResult != DialogResult.Abort) { string filePath = SaveExcel.FileName; Class1.ExportExcelData(filePath, chart1); } }
// 创建excel private int CreateExcel() { //获取该风机点的所有数据 List <FanPoint> fanDate = FanPointDAL.GetDateOfSingleFanByDate(windFieldOfFan.BranchTableName, this.WindFieldName, this.FanNumber, startTime, endTime); //设置excel的标题名 string excelTitle = this.CompanyName + "---" + this.WindFieldName + this.FanNumber + "号风机数据(" + fanDate[0].DateTime + "-" + fanDate[fanDate.Count - 1].DateTime + ")"; //设置地址 string address = "地址:" + windFieldOfFan.Province + windFieldOfFan.City + windFieldOfFan.DetailAddress; //创建EXCEL bool excelResult = SaveExcel.CreateExcel(filePath, excelTitle, address, fanDate, epg); return(0); }
/// <summary> /// 按模板方式导出无返回值 /// </summary> /// <param name="TempName"></param> /// <param name="Value"></param> /// <param name="sp"></param> public void ExportExcel(string TempName, string Value) { var list = Newtonsoft.Json.Linq.JObject.Parse(Value); Dictionary <string, JArray> jarrays = new Dictionary <string, JArray>(); string username = UtilFunction.GetCookie("uname"); foreach (var arry in list) { jarrays.Add(arry.Key, arry.Value as JArray); } SaveParameter sp = new SaveParameter(jarrays, TempName, username); SaveExcel SaveExcel = new SaveExcel(); SaveExcel.RunSave(sp); }
private void btnOutToExcel_Click(object sender, EventArgs e) { string SaveFilename = ""; if (SaveExcel.ShowDialog() != DialogResult.OK) { return; } else { SaveFilename = SaveExcel.FileName; } string errstr = ""; DataGridViewExportToExcel(dsShow.Tables[0], SaveFilename, ref errstr); }
//<summary> //按模板方式导出无返回值 //</summary> //<param name="TempNames">模板名称(N个模板)</param> //<param name="ds">DataSet</param> public void ExportExcel(List <string> TempNames, DataSet ds, Dictionary <string, DataRow> dicAuditRules) { SaveParameter sp = new SaveParameter(TempNames, ds, dicAuditRules); SaveExcel SaveExcel = new SaveExcel(); SaveExcel.RunSave(sp); FileLog.WriteLog("测试(start):SaveExcel.State=" + SaveExcel.State); while (true) { FileLog.WriteLogNotLine("."); if (SaveExcel.State > 1) { return; } } }
private void Save_Exel(object sender, RoutedEventArgs e) { ISave save = new SaveExcel(); save.Save(Model); }
private void Button_Click_1(object sender, RoutedEventArgs e) { SaveExcel saveExcel = new SaveExcel(); saveExcel.Save(dataGridView1); }
private void btnOutToExcel_Click(object sender, EventArgs e) { string SaveFilename = ""; if (SaveExcel.ShowDialog() != DialogResult.OK) { return; } else { SaveFilename = SaveExcel.FileName; } string errstr = ""; // DataGridViewExportToExcel(dsShow.Tables[0], SaveFilename, ref errstr); //} //public static bool DataGridViewExportToExcel(DataTable mDataTable, String strFileName, ref String strMsg) //{ // strMsg = ""; // // 创建Excel对象 // Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); // //Microsoft.Office.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass(); // if (xlApp == null) // { // strMsg = "Excel无法启动"; // return false; // } // // 创建Excel工作薄 // Microsoft.Office.Interop.Excel.Workbook xlBook = xlApp.Workbooks.Add(true); // Microsoft.Office.Interop.Excel.Worksheet xlSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlBook.Worksheets[1]; // Microsoft.Office.Interop.Excel.Range range = null; // /* // // 设置标题 // range = xlSheet.get_Range(xlApp.Cells[1,1],xlApp.Cells[1,ts.GridColumnStyles.Count]); // range.MergeCells = true; // xlApp.ActiveCell.FormulaR1C1 = p_ReportName; // xlApp.ActiveCell.Font.Size = 20; // xlApp.ActiveCell.Font.Bold = true; // xlApp.ActiveCell.HorizontalAlignment = Excel.Constants.xlCenter; // */ // // 列索引,行索引,总列数,总行数 // int colIndex = 0; // int RowIndex = 0; // int colCount = mDataTable.Columns.Count; // int RowCount = mDataTable.Rows.Count + 1; // // 创建缓存数据 // object[,] objData = new object[RowCount + 1, colCount]; // // 获取列标题 // foreach (DataColumn dc in mDataTable.Columns) // { // objData[RowIndex, colIndex++] = dc.ColumnName; // } // // 获取数据 // for (RowIndex = 1; RowIndex < RowCount; RowIndex++) // { // for (colIndex = 0; colIndex < colCount; colIndex++) // { // objData[RowIndex, colIndex] = mDataTable.Rows[RowIndex - 1][colIndex].ToString(); // } // } // // 写入Excel // //((Excel.Range)xlSheet.Columns["A:A ",System.Reflection.Missing.Value]).ColumnWidth = 16; // range = xlSheet.get_Range(xlApp.Cells[1, 1], xlApp.Cells[RowCount, colCount]); // range.Value2 = objData; // range = (Microsoft.Office.Interop.Excel.Range)xlSheet.Columns["A:B", System.Type.Missing]; // range.ColumnWidth = 20; // // 保存 // try // { // xlBook.Saved = true; // xlBook.SaveCopyAs(strFileName); // MessageBox.Show("数据转存为Excel成功"); // } // catch (Exception ee) // { // strMsg = ee.Message; // return false; // } // finally // { // range = null; // xlSheet = null; // xlBook = null; // xlApp.Quit(); // xlApp = null; // GC.Collect(); // } // return true; }