private void BindGrid1() { if (Grid2.SelectedRowIndex < 0) { return; } int classId = Convert.ToInt32(Grid2.DataKeys[Grid2.SelectedRowIndex][0]); DataTable table = null; if (classId == 101) { table = DataSourceUtil.GetDataTable(); } else { table = DataSourceUtil.GetDataTable2(); } Grid1.DataSource = table; Grid1.DataBind(); UpdateClassDesc(classId); }
/// <summary> /// 模拟数据库分页(实际项目中请直接使用SQL语句返回分页数据!) /// </summary> /// <returns></returns> private DataTable GetSortedPagedDataTable(string sortField, string sortDirection, int pageIndex, int pageSize) { DataTable source = DataSourceUtil.GetDataTable2(); // 先排序 DataView view1 = source.DefaultView; view1.Sort = String.Format("{0} {1}", sortField, sortDirection); DataTable sortedTable = view1.ToTable(); // 再分页 DataTable paged = sortedTable.Clone(); int rowbegin = pageIndex * pageSize; int rowend = (pageIndex + 1) * pageSize; if (rowend > sortedTable.Rows.Count) { rowend = sortedTable.Rows.Count; } for (int i = rowbegin; i < rowend; i++) { paged.ImportRow(sortedTable.Rows[i]); } return(paged); }
private void listView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { if (listView.SelectedItems.Count > 1) { List <string> dataSourceList = new List <string>(); foreach (ListViewItem item in listView.SelectedItems) { if (!DataSourceUtil.IsFolderType(item.SubItems[1].Text)) { // ReSharper disable LocalizableElement dataSourceList.Add(string.Format("\"{0}\"", GetItemPath(item))); } // ReSharper restore LocalizableElement } sourcePathTextBox.Text = string.Join(@" ", dataSourceList.ToArray()); } else if (listView.SelectedItems.Count > 0) { sourcePathTextBox.Text = GetItemPath(listView.SelectedItems[0]); } else { sourcePathTextBox.Text = string.Empty; } }
// 表格过滤 public DataTable GetFilteredTable(JArray filteredData) { // 示例使用的模拟数据是一次性返回的,因此我们需要新建一个 DataTable 来过滤返回的数据 // 注:实际应用环境请不要这么做!!!(可以将过滤条件直接用于数据库检索) DataTable source = DataSourceUtil.GetDataTable(); DataTable result = source.Clone(); foreach (DataRow row in source.Rows) { bool filtered = true; foreach (JObject filteredObj in filteredData) { if (!CheckDataRow(row, filteredObj)) { filtered = false; break; } } if (filtered) { result.Rows.Add(row.ItemArray); } } return(result); }
private SourceInfo getSourceInfo(DirectoryInfo dirInfo) { string type = DataSourceUtil.GetSourceType(dirInfo); SourceInfo sourceInfo = new SourceInfo(new MsDataFilePath(dirInfo.FullName)) { type = type, imageIndex = (DataSourceUtil.IsFolderType(type) ? ImageIndex.Folder : ImageIndex.MassSpecFile), name = dirInfo.Name, dateModified = GetSafeDateModified(dirInfo) }; if (listView.View != View.Details || (sourceTypeComboBox.SelectedIndex > 0 && sourceTypeComboBox.SelectedItem.ToString() != sourceInfo.type)) { return(sourceInfo); } if (sourceInfo.isFolder) { return(sourceInfo); } if (!sourceInfo.isUnknown) { sourceInfo.size = 0; foreach (FileInfo fileInfo in dirInfo.GetFiles()) { sourceInfo.size += (UInt64)fileInfo.Length; } return(sourceInfo); } return(null); }
private void BindGrid2() { Grid2.DataSource = DataSourceUtil.GetClassDataTable(); Grid2.DataBind(); Grid2.SelectedRowIndex = 0; }
private DataTable GetSource(string ttbSearch, string rblAtSchool) { DataTable table2 = DataSourceUtil.GetDataTable2(); DataView view2 = table2.DefaultView; List <string> filters = new List <string>(); if (!String.IsNullOrEmpty(ttbSearch)) { // RowFilter的用法:http://www.csharp-examples.net/dataview-rowfilter/ filters.Add(String.Format("Name LIKE '*{0}*'", DataSourceUtil.EscapeLikeValue(ttbSearch))); } if (rblAtSchool != "-1") { filters.Add(String.Format("AtSchool = {0}", rblAtSchool)); } if (filters.Count > 0) { // RowFilter的用法:http://www.csharp-examples.net/dataview-rowfilter/ view2.RowFilter = String.Join(" AND ", filters.ToArray()); } return(view2.ToTable()); }
private void FindDataFiles(string directory, bool overwrite, ILongWaitBroker longWaitBroker) { // Don't search if every spectrum source file has an exact match and an alternate match if (directory == null || !Directory.Exists(directory) || (!overwrite && SpectrumSourceFiles.Values.All(s => s.HasMatches))) { return; } if (longWaitBroker != null) { longWaitBroker.Message = string.Format(Resources.ImportResultsControl_FindResultsFiles_Searching_for_matching_results_files_in__0__, directory); } try { foreach (string entry in Directory.EnumerateFileSystemEntries(directory)) { if (longWaitBroker != null && longWaitBroker.IsCanceled) { return; } if (entry != null && DataSourceUtil.IsDataSource(entry)) { TryMatch(entry, overwrite); } } } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { // No permissions on folder } }
/// <summary> /// 模拟数据库分页 /// </summary> /// <returns></returns> private DataTable GetPagedDataTable() { int pageIndex = Grid1.PageIndex; int pageSize = Grid1.PageSize; string sortField = Grid1.SortField; string sortDirection = Grid1.SortDirection; DataTable table2 = DataSourceUtil.GetDataTable2(); DataView view2 = table2.DefaultView; view2.Sort = String.Format("{0} {1}", sortField, sortDirection); DataTable table = view2.ToTable(); DataTable paged = table.Clone(); int rowbegin = pageIndex * pageSize; int rowend = (pageIndex + 1) * pageSize; if (rowend > table.Rows.Count) { rowend = table.Rows.Count; } for (int i = rowbegin; i < rowend; i++) { paged.ImportRow(table.Rows[i]); } return(paged); }
private MsDataFilePath[] GetWiffSubPaths(string filePath) { using (var longWaitDlg = new LongWaitDlg { Text = Resources.ImportResultsDlg_GetWiffSubPaths_Sample_Names, Message = string.Format(Resources.ImportResultsDlg_GetWiffSubPaths_Reading_sample_names_from__0__, Path.GetFileName(filePath)) }) { string[] dataIds = null; try { longWaitDlg.PerformWork(this, 800, () => dataIds = MsDataFileImpl.ReadIds(filePath)); } catch (Exception x) { string message = TextUtil.LineSeparate( string.Format(Resources.ImportResultsDlg_GetWiffSubPaths_An_error_occurred_attempting_to_read_sample_information_from_the_file__0__, filePath), Resources.ImportResultsDlg_GetWiffSubPaths_The_file_may_be_corrupted_missing_or_the_correct_libraries_may_not_be_installed, x.Message); MessageDlg.ShowWithException(this, message, x); } return(DataSourceUtil.GetWiffSubPaths(filePath, dataIds, ChooseSamples)); } }
private DataTable GetSource(string ddlAtSchool, JArray filteredData) { DataTable table2 = DataSourceUtil.GetDataTable2(); DataView view2 = table2.DefaultView; List <string> filters = new List <string>(); // 表格工具栏中的下拉列表过滤项 if (ddlAtSchool != "-1") { filters.Add(String.Format("AtSchool = {0}", ddlAtSchool)); } // 表头菜单的过滤项 if (filteredData != null && filteredData.Count > 0) { foreach (JObject filteredObj in filteredData) { // 本过滤项是[所学专业]列的过滤项 string columnID = filteredObj.Value <string>("column"); if (columnID == "Major") { JObject item = filteredObj.Value <JObject>("item"); string itemOperator = item.Value <string>("operator"); string itemValue = item.Value <string>("value"); if (!String.IsNullOrEmpty(itemValue)) { string escapedValue = DataSourceUtil.EscapeLikeValue(itemValue); if (itemOperator == "equal") { filters.Add(String.Format("Major = '{0}'", escapedValue)); } else if (itemOperator == "contain") { filters.Add(String.Format("Major LIKE '*{0}*'", escapedValue)); } else if (itemOperator == "start") { filters.Add(String.Format("Major LIKE '{0}*'", escapedValue)); } else if (itemOperator == "end") { filters.Add(String.Format("Major LIKE '*{0}'", escapedValue)); } } } } } if (filters.Count > 0) { // RowFilter的用法:http://www.csharp-examples.net/dataview-rowfilter/ view2.RowFilter = String.Join(" AND ", filters.ToArray()); } return(view2.ToTable()); }
// GET: GridDataUrl/GridDataUrlData public ActionResult Index(bool?data2) { JArray ja = new JArray(); DataTable source = null; if (data2.HasValue && data2.Value) { source = DataSourceUtil.GetDataTable2(); } else { source = DataSourceUtil.GetDataTable(); } foreach (DataRow row in source.Rows) { JObject jo = new JObject(); jo.Add("Id", (int)row["Id"]); jo.Add("Name", row["Name"].ToString()); jo.Add("Gender", (int)row["Gender"]); jo.Add("EntranceYear", (int)row["EntranceYear"]); jo.Add("AtSchool", (bool)row["AtSchool"]); jo.Add("Major", row["Major"].ToString()); jo.Add("Group", (int)row["Group"]); ja.Add(jo); } return(Content(ja.ToString(Newtonsoft.Json.Formatting.None))); }
public static string GetDatasourcePath(IFeature feature) { IWorkspace ws = GetWorkspace(feature); string dsPath = DataSourceUtil.GetDataSourcePath(ws); return(dsPath); }
public static string GetDatasourcePath(IRow row) { IWorkspace ws = GetWorkspace(row); string dsPath = DataSourceUtil.GetDataSourcePath(ws); return(dsPath); }
private DataTable GetFilteredData(string gender, string[] majors) { DataTable table = DataSourceUtil.GetDataTable(); DataView view = table.DefaultView; List <string> filters = new List <string>(); // 性别过滤 if (!String.IsNullOrEmpty(gender)) { filters.Add(String.Format("Gender = {0}", gender)); } // 专业过滤 if (majors != null && majors.Length > 0) { List <string> majorFilters = new List <string>(); foreach (string ddb in majors) { majorFilters.Add(String.Format("Major = '{0}'", ddb)); } filters.Add("(" + String.Join(" OR ", majorFilters.ToArray()) + ")"); } if (filters.Count > 0) { view.RowFilter = String.Join(" AND ", filters.ToArray()); } return(table); }
public KeyValuePair <string, MsDataFileUri[]>[] GetDataSourcePathsFileSingle(string name, IEnumerable <MsDataFileUri> dataSources) { var listPaths = new List <MsDataFileUri>(); foreach (var dataSource in dataSources) { MsDataFilePath msDataFilePath = dataSource as MsDataFilePath; // Only .wiff files currently support multiple samples per file. // Keep from doing the extra work on other types. if (null != msDataFilePath && DataSourceUtil.IsWiffFile(msDataFilePath.FilePath)) { var paths = GetWiffSubPaths(msDataFilePath.FilePath); if (paths == null) { return(null); // An error or user cancelation occurred } listPaths.AddRange(paths); } else { listPaths.Add(dataSource); } } return(new[] { new KeyValuePair <string, MsDataFileUri[]>(name, listPaths.ToArray()) }); }
// GET: GridDataUrl/TreeGridData public ActionResult Index() { JArray ja = new JArray(); DataTable source = DataSourceUtil.GetTreeDataTable(); foreach (DataRow row in source.Rows) { JObject jo = new JObject(); jo.Add("ParentId", (int)row["ParentId"]); jo.Add("Id", (int)row["Id"]); jo.Add("Name", row["Name"].ToString()); jo.Add("Type", row["Type"].ToString()); jo.Add("ModifyDate", (DateTime)row["ModifyDate"]); object fileSize = row["Size"]; if (fileSize == DBNull.Value) { jo.Add("Size", ""); } else { jo.Add("Size", (int)fileSize); } ja.Add(jo); } return(Content(ja.ToString(Newtonsoft.Json.Formatting.None))); }
public KeyValuePair <string, MsDataFileUri[]>[] GetDataSourcePathsFileReplicates(IEnumerable <MsDataFileUri> dataSources) { var listNamedPaths = new List <KeyValuePair <string, MsDataFileUri[]> >(); foreach (var dataSource in dataSources) { MsDataFilePath msDataFilePath = dataSource as MsDataFilePath; // Only .wiff files currently support multiple samples per file. // Keep from doing the extra work on other types. if (null != msDataFilePath && DataSourceUtil.IsWiffFile(msDataFilePath.FilePath)) { var paths = GetWiffSubPaths(msDataFilePath.FilePath); if (paths == null) { return(null); // An error or user cancelation occurred } // Multiple paths then add as samples if (paths.Length > 1 || // If just one, make sure it has a sample part. Otherwise, // drop through to add the entire file. (paths.Length == 1 && paths[0].SampleName != null)) { foreach (var path in paths) { listNamedPaths.Add(new KeyValuePair <string, MsDataFileUri[]>( path.SampleName, new MsDataFileUri[] { path })); } continue; } } listNamedPaths.Add(new KeyValuePair <string, MsDataFileUri[]>( dataSource.GetFileNameWithoutExtension(), new[] { dataSource })); } return(listNamedPaths.ToArray()); }
/// <summary> /// 模拟数据库分页(实际项目中请直接使用SQL语句返回分页数据!) /// </summary> /// <returns></returns> private DataTable GetPagedDataTable(int pageIndex, int pageSize, bool?data2) { DataTable source = null; if (data2.HasValue && data2.Value) { source = DataSourceUtil.GetDataTable2(); } else { source = DataSourceUtil.GetDataTable(); } DataTable paged = source.Clone(); int rowbegin = pageIndex * pageSize; int rowend = (pageIndex + 1) * pageSize; if (rowend > source.Rows.Count) { rowend = source.Rows.Count; } for (int i = rowbegin; i < rowend; i++) { paged.ImportRow(source.Rows[i]); } return(paged); }
public KeyValuePair <string, MsDataFileUri[]>[] GetDataSourcePathsDir() { string initialDir = Path.GetDirectoryName(_documentSavedPath); using (FolderBrowserDialog dlg = new FolderBrowserDialog { Description = Resources.ImportResultsDlg_GetDataSourcePathsDir_Results_Directory, ShowNewFolderButton = false, SelectedPath = initialDir }) { if (dlg.ShowDialog(this) != DialogResult.OK) { return(null); } string dirRoot = dlg.SelectedPath; Settings.Default.SrmResultsDirectory = dirRoot; KeyValuePair <string, MsDataFileUri[]>[] namedPaths = DataSourceUtil.GetDataSourcesInSubdirs(dirRoot).ToArray(); if (namedPaths.Length == 0) { MessageBox.Show(this, string.Format(Resources.ImportResultsDlg_GetDataSourcePathsDir_No_results_found_in_the_folder__0__, dirRoot), Program.Name); return(null); } return(namedPaths); } }
public ActionResult ExportInBondExBondRawMaterialReport(int?SearchBonderID, Nullable <System.DateTime> SearchFromDate, Nullable <System.DateTime> SearchToDate) { if (null != SearchBonderID && null != SearchFromDate && null != SearchToDate) { List <INBOND> inbondList = getInbondList(SearchBonderID, SearchFromDate, SearchToDate); List <BonderInfo> bonderInfoList = new List <BonderInfo>(); BonderInfo bonderInfo = null; foreach (var inbondInfo in inbondList) { bonderInfo = new BonderInfo(); bonderInfo.BonderName = inbondInfo.BONDER.BONDERNAME; bonderInfo.BonderLCNo = inbondInfo.LCNUMBER; for (int i = 0; i < inbondInfo.INBONDRAWMATERIALs.Count; i++) { RawMaterialInfo rw = new RawMaterialInfo(); rw.BonderID = (short)inbondInfo.BONDERID; rw.RawMaterialName = inbondInfo.INBONDRAWMATERIALs[i].MATERIAL.MHSCODE; rw.HSCode = inbondInfo.INBONDRAWMATERIALs[i].MATERIAL.MHSCODE; bonderInfo.RawMaterialInfoList.Add(rw); } bonderInfoList.Add(bonderInfo); } ReportDocument rd = new ReportDocument(); rd.Load(Path.Combine(Server.MapPath("~/Report/Crystal"), "InBondExBondRawMaterialStatus_1.rpt")); rd.SetDataSource(DataSourceUtil.ToDataSet(bonderInfoList)); rd.SetDatabaseLogon("", "", "", ""); Response.Buffer = false; Response.ClearContent(); Response.ClearHeaders(); //rd.SetDatabaseLogon("", "", "192.168.40.55:1521/orcl", ""); try { Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); stream.Seek(0, SeekOrigin.Begin); return(File(stream, "application/pdf", "InBondRawMaterial.pdf")); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("ExportInBondExBondRawMaterialReport: Time-" + DateTime.Now + " Exception = " + e.ToString()); ViewBag.ErrorMsg = "Export InBondExBond Rawmaterial Report Development is On going"; throw e; } } //return Redirect(ControllerContext.HttpContext.Request.UrlReferrer.ToString()); ViewBag.BonderID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME"); return(View("InbondExbondRawMaterialStatus")); }
public void InitializeSpectrumSourceFiles(SrmDocument document) { if (!IsDDASearch) { if (DocLib == null) { return; } var measuredResults = document.Settings.MeasuredResults; foreach (var dataFile in DocLib.LibraryFiles.FilePaths) { var msDataFilePath = new MsDataFilePath(dataFile); SpectrumSourceFiles[dataFile] = new FoundResultsFilePossibilities(msDataFilePath.GetFileNameWithoutExtension()); // If a matching file is already in the document, then don't include // this library spectrum source in the set of files to find. if (measuredResults != null && measuredResults.FindMatchingMSDataFile(MsDataFileUri.Parse(dataFile)) != null) { continue; } if (File.Exists(dataFile) && DataSourceUtil.IsDataSource(dataFile)) { // We've found the dataFile in the exact location // specified in the document library, so just add it // to the "FOUND" list. SpectrumSourceFiles[dataFile].ExactMatch = msDataFilePath.ToString(); } } DocLib.ReadStream.CloseStream(); } }
// GET: GridDataUrl/PagingSummaryCurrentPageData public ActionResult Index() { JArray ja = new JArray(); DataTable source = DataSourceUtil.GetDataTable2(); foreach (DataRow row in source.Rows) { int fee = (int)row["Fee"]; int donate = (int)row["Donate"]; JObject jo = new JObject(); jo.Add("Id", (int)row["Id"]); jo.Add("Name", row["Name"].ToString()); jo.Add("Gender", (int)row["Gender"]); jo.Add("EntranceYear", (int)row["EntranceYear"]); jo.Add("AtSchool", (bool)row["AtSchool"]); jo.Add("Major", row["Major"].ToString()); jo.Add("Fee", fee); jo.Add("Donate", donate); ja.Add(jo); } return(Content(ja.ToString(Newtonsoft.Json.Formatting.None))); }
private void BindGrid() { DataTable table = DataSourceUtil.GetDataTable(); Grid1.DataSource = table; Grid1.DataBind(); }
/// <summary> /// 模拟数据库分页(实际项目中请直接使用SQL语句返回分页数据!) /// </summary> /// <returns></returns> private DataTable GetPagedDataTable(int pageIndex, int pageSize, int recordCount) { DataTable source = DataSourceUtil.GetTreeDataTable(); DataTable topTable = GetTopNodeTable(source); DataTable paged = source.Clone(); int rowbegin = pageIndex * pageSize; int rowend = (pageIndex + 1) * pageSize; if (rowend > recordCount) { rowend = recordCount; } for (int i = rowbegin; i < rowend; i++) { DataRow topTableRow = topTable.Rows[i]; paged.ImportRow(topTableRow); ImportCurrentPageTable(source, paged, Convert.ToInt32(topTableRow["Id"])); } return(paged); }
// 模拟在服务器端保存数据 // 特别注意:在真实的开发环境中,不要在Session放置大量数据,否则会严重影响服务器性能 private DataTable GetSourceData() { if (Session[KEY_FOR_DATASOURCE_SESSION] == null) { Session[KEY_FOR_DATASOURCE_SESSION] = DataSourceUtil.GetDataTable(); } return((DataTable)Session[KEY_FOR_DATASOURCE_SESSION]); }
// GET: Grid/ExcelGroupField/ExportToExcel public ActionResult ExportToExcel(JArray content) { DataTable source = DataSourceUtil.GetDataTable(); //string TH_HTML = "<th>{0}</th>"; string TD_HTML = "<td>{0}</td>"; //string TD_IMAGE_HTML = "<td><img src=\"{0}\"></td>"; StringBuilder sb = new StringBuilder(); sb.Append("<meta http-equiv=\"Content-Type\" content=\"application/vnd.ms-excel;charset=utf-8\"/>"); sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">"); MultiHeaderTable mht = new MultiHeaderTable(); mht.ResolveMultiHeaderTable(content); foreach (List <object[]> rows in mht.MultiTable) { sb.Append("<tr>"); foreach (object[] cell in rows) { int rowspan = Convert.ToInt32(cell[0]); int colspan = Convert.ToInt32(cell[1]); JObject column = cell[2] as JObject; sb.AppendFormat("<th{0}{1}{2}>{3}</th>", rowspan != 1 ? " rowspan=\"" + rowspan + "\"" : "", colspan != 1 ? " colspan=\"" + colspan + "\"" : "", colspan != 1 ? " style=\"text-align:center;\"" : "", column.Value <string>("text")); } sb.Append("</tr>"); } int rowIndex = 1; foreach (DataRow row in source.Rows) { sb.Append("<tr>"); sb.AppendFormat(TD_HTML, rowIndex++); sb.AppendFormat(TD_HTML, row["Name"]); sb.AppendFormat(TD_HTML, row["Gender"].ToString() == "1" ? "男" : "女"); sb.AppendFormat(TD_HTML, row["ChineseScore"]); sb.AppendFormat(TD_HTML, row["MathScore"]); sb.AppendFormat(TD_HTML, row["TotalScore"]); sb.AppendFormat(TD_HTML, row["Major"]); sb.AppendFormat(TD_HTML, ((DateTime)row["LogTime"]).ToString("yyyy-MM-dd")); sb.Append("</tr>"); } sb.Append("</table>"); return(File(Encoding.UTF8.GetBytes(sb.ToString()), "application/vnd.ms-excel", "myexcel.xls")); }
private void BindGrid() { DataTable table = DataSourceUtil.GetDataTable(); Grid1.DataSource = table; Grid1.DataBind(); Grid1.SelectedRowIndexArray = new int[] { 4, 9 }; }
private void BindGrid() { ViewState["UseDataSource1"] = true; DataTable table = DataSourceUtil.GetDataTable(); Grid1.DataSource = table; Grid1.DataBind(); }
// GET/POST 都可以 public ActionResult ExportToExcel(JObject content) { Dictionary <string, int> contentDic = content.ToObject <Dictionary <string, int> >(); DataTable source = DataSourceUtil.GetDataTable(); string TH_HTML = "<th>{0}</th>"; string TD_HTML = "<td>{0}</td>"; string TD_IMAGE_HTML = "<td><img src=\"{0}\"></td>"; StringBuilder sb = new StringBuilder(); sb.Append("<meta http-equiv=\"Content-Type\" content=\"application/vnd.ms-excel;charset=utf-8\"/>"); sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">"); sb.Append("<tr>"); sb.AppendFormat(TH_HTML, ""); sb.AppendFormat(TH_HTML, "姓名"); sb.AppendFormat(TH_HTML, "性别"); sb.AppendFormat(TH_HTML, "入学年份"); sb.AppendFormat(TH_HTML, "是否在校"); sb.AppendFormat(TH_HTML, "所学专业"); sb.AppendFormat(TH_HTML, "分组"); sb.AppendFormat(TH_HTML, "语文成绩"); sb.Append("</tr>"); int rowIndex = 1; foreach (DataRow row in source.Rows) { string rowId = row["Id"].ToString(); sb.Append("<tr>"); sb.AppendFormat(TD_HTML, rowIndex++); sb.AppendFormat(TD_HTML, row["Name"]); sb.AppendFormat(TD_HTML, row["Gender"].ToString() == "1" ? "男" : "女"); sb.AppendFormat(TD_HTML, row["EntranceYear"]); sb.AppendFormat(TD_HTML, (bool)row["AtSchool"] ? "√" : "×"); sb.AppendFormat(TD_HTML, row["Major"]); sb.AppendFormat(TD_IMAGE_HTML, GetAbsoluteUrl(String.Format("~/res/images/16/{0}.png", row["Group"]))); if (contentDic.ContainsKey(rowId)) { sb.AppendFormat(TD_HTML, contentDic[rowId]); } else { // 未找到! sb.AppendFormat(TD_HTML, ""); } sb.Append("</tr>"); } sb.Append("</table>"); return(File(Encoding.UTF8.GetBytes(sb.ToString()), "application/vnd.ms-excel", "myexcel.xls")); }