Tag: asp.net mvc 4

需要创buildExcel文件并保存在本地path中。 在C#MVC

我有这个代码…但它要求在一个对话框中保存文件或打开文件选项。 string attachment = "attachment; filename=XYZ.xls"; Response.ClearContent(); Response.ContentType = "application/ms-excel"; Response.AddHeader("Content-disposition", attachment); ….. ….. 我想使用我的代码生成Exceldynamic,并保存在我的驱动器的本地文件夹。

将CSV文件导出到Excel 2007

我有一些代码将数据结果作为CSV发送给用户。 这对Excel 2013工作正常,但在Excel 2007中,它不会拆分成列,而是作为只插入到一列中的数据。 有没有办法告诉Excel如何拆分文本(它被分隔)? 这是我的代码: public async Task ExcelResultList(int id) { var asString = await Resolver.Resolve<IHandoutManager>().GetResultListAsStringAsync(id); var handout = await Resolver.Resolve<IHandoutManager>().GetHandout(id); var filename = string.Format("{0} registrations – {1:yyyy-MM-dd}.csv", handout.Name, DateTime.Now); var contenttype = "application/csv"; Response.Clear(); Response.ContentType = contenttype; Response.AddHeader("content-disposition", "attachment;filename=" + filename); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentEncoding = Encoding.Unicode; Response.Write(asString); Response.End(); }

下载文件时如何设置文件名?

我正在使用MVC 4.我使用以下简单的代码dynamic生成Excel文件。 我的托pipe在Azure上。 我创build了一个根path,然后尝试保存该Excel文件。 问题是当我的ActionResult方法响应回来它给予默认的popup来打开一个文件,但文件名是有一个GUID而不是我提供的文件名。 Excel文件生成代码: Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); // … //Save LocalResource resource = RoleEnvironment.GetLocalResource("MyValue"); string tempPath = resource.RootPath + "DemoFile.xls"; return tempPath; tempPath返回类似于C:\AppData\Local\dftmp\Resources\11a2435c-998c-4fe8-aa55-8bb42455b4ca\directory\DemoFile.xls 。 下载文件popup不会给文件名作为DemoFile它gives some GUID为什么这样? ActionResult方法代码: public ActionResult DownloadExcel() { string path = ExcelGenerationCode(fileName); Stream s = new FileStream(path, FileMode.Open, FileAccess.Read); return new FileStreamResult(s, "application/vnd.ms-excel"); } 也试图给名称属性 public ActionResult […]

如何保存在C#中的Excel文件

我正在创build一个MVC控制器的行动,其中传递给该方法的JSON数据将写入一个Excel文件。 现在,我通过基于本博客文章中的示例使用来自数据表的硬编码数据来testingfunction。 这里是我有的代码: [HttpPost] public ActionResult ExportData() { Microsoft.Office.Interop.Excel.Application excel; Microsoft.Office.Interop.Excel.Workbook worKbooK; Microsoft.Office.Interop.Excel.Worksheet worKsheeT; Microsoft.Office.Interop.Excel.Range celLrangE; try { excel = new Microsoft.Office.Interop.Excel.Application(); excel.Visible = false; excel.DisplayAlerts = false; worKbooK = excel.Workbooks.Add(Type.Missing); worKsheeT = (Microsoft.Office.Interop.Excel.Worksheet)worKbooK.ActiveSheet; worKsheeT.Name = "StudentRepoertCard"; worKsheeT.Range[worKsheeT.Cells[1, 1], worKsheeT.Cells[1, 8]].Merge(); worKsheeT.Cells[1, 1] = "Student Report Card"; worKsheeT.Cells.Font.Size = 15; int rowcount = 2; foreach […]

GemBox – 滚动到视图function丢失?

我第一次使用GemBox(版本3.5),有一个问题。 打开生成的XLSX文件时,它始终滚动到工作表的底部。 我(或者说,我的客户)希望它从左上angular开始。 有没有什么办法可以编程设置顶部可见单元格保存之前,即“滚动到视图”或“滚动到顶部”function? 我还没有发现任何在GemBox文档或在解决这个问题的interwebs。

打开xml sdk,读取excel公式单元格

我有单元格C4中有公式= SUM(C2:C3)的excel文件。 我分别在单元格C2和C3中有值15和17。 以编程方式,我希望能够执行C4公式并返回值32(公式的结果)。 有人build议我应该使用OpenXml SDK。 因为这个代码将被Windows Azure网站托pipe和使用。 这是我的代码到目前为止,单元格不在C4中执行公式。 string filename = Server.MapPath("/") + "ExcelData.xlsx"; using (SpreadsheetDocument document = SpreadsheetDocument.Open(filename, true)) { document.WorkbookPart.Workbook.CalculationProperties.ForceFullCalculation = true; document.WorkbookPart.Workbook.CalculationProperties.FullCalculationOnLoad = true; Sheet sheet = document.WorkbookPart.Workbook.Descendants<Sheet>().SingleOrDefault(s => s.Name == "myRange1"); if (sheet == null) { throw new ArgumentException( String.Format("No sheet named {0} found in spreadsheet {1}", "myRange1", filename), "sheetName"); […]

别名与列中的空间使用linq和gridview导出excel

我需要导出Excel,我正在使用MVC4 这是我的代码 var co = from c in context.AN_COMPANY orderby c.COMPANY_DESCR select c; List<AN_COMPANY_EXT> societa_list = new List<AN_COMPANY_EXT>(); foreach (var o in co) { AN_COMPANY_EXT c_ex = new AN_COMPANY_EXT(o); societa_list.Add(c_ex); } GridView gv = new GridView(); gv.DataSource = (from d in societa_list select new { Codice = d.ID_COMPANY, Descrizione = d.COMPANY_DESCR, SAP_Alias = d.COMPANY_SAP_ALIAS, Booking_Company […]

stream出大数据表excel文件

我试图stream出一个数据表到MVC的Excel文件。 当行数超过25万时,它给我OutOfMemoryexception。 以下是代码: var memStream = new MemoryStream(); var streamWriter = new StreamWriter(memStream); streamWriter.WriteLine("{0}", "<TABLE>"); foreach (DataRow rw in dt.Rows) { streamWriter.WriteLine("{0}", "<TR>"); foreach (DataColumn cl in dt.Columns) { streamWriter.WriteLine("{0}", "<TD>"); streamWriter.WriteLine("{0}", rw[cl].ToString()); streamWriter.WriteLine("{0}", "</TD>"); } streamWriter.WriteLine("{0}", "</TR>"); } streamWriter.WriteLine("{0}", "</TABLE>"); streamWriter.Flush(); memStream.Seek(0, SeekOrigin.Begin); return File(memStream, "application/vnd.ms-excel", "Test.xls"); 我认为通过缓冲区写入内存stream应该解决OutOfMemory问题。 但是,我还没有这样做。 我应该如何修改上面的代码缓冲写入内存stream? 谢谢

MVC4:导出qrcode图像到Excel表单

我想用我的表格中的qr-code图像导出excel表格。 qrcode保存与序列号,我生成与谷歌apis。 我在控制器中返回MvcHtmlString并在我的视图中使用它,如@Html.QRCode(item.SerialNumber, 80, 0) ,它在我的视图中工作良好。 我的控制器 public static MvcHtmlString QRCode(this HtmlHelper htmlHelper, string data, int size = 80, int margin = 4, QRCodeErrorCorrectionLevel errorCorrectionLevel = QRCodeErrorCorrectionLevel.Low, object htmlAttributes = null) { if (data == null) throw new ArgumentNullException("data"); if (size < 1) throw new ArgumentOutOfRangeException("size", size, "Must be greater than zero."); if (margin < […]

有没有办法找出一个Excel 2007/2010文件是否使用SpreadSheetGear 2012 for C#Asp.net MVC密码保护?

现在我们使用exception消息触发一个消息对话框,当Excel文件被密码保护,但我想知道是否有更好的方法来处理这个问题。 我们只是想检查提供的Excel文件是否受密码保护,不打开它,并触发警告消息。 我们使用C#Asp.net MVC 4.任何帮助,将不胜感激。