Tag: asp.net web api

从streamAsp.Net核心WebAPI读取Excel文件

我正在使用asp.net核心webapi,我想从客户端(使用Angular 2)发布一个excel文件到我的控制器。 我读过导入Excel的例子,但他们所做的是使用现有的文件。 我想知道如何使用IO.Stream读取一个excel文件。 谢谢你的帮助。 我已经开始阅读一个.txt文件,如下所示: public string Post() { var files = Request.Form.Files; if(files != null) { var stream = files[0].OpenReadStream(); StreamReader reader = new StreamReader(stream); string result = reader.ReadToEnd(); int a; return result; } return ""; }

使用ASP.Net MVC Web Api将JSON数据导出到Excel工作表

我有一个单页面应用程序(SPA)使用Durandal,ASP.net MVC Web API,微风和淘汰js。 我需要将一个列表导出到一个Excel表格,该表格应该被下载到下载文件夹,只需点击html页面上的一个button即可。 虽然我已经成功地通过在JavaScript(在客户端)将JSON数据转换为csv格式来完成,但是如果数据量很大(3000 +行或可以是12000左右),则花费的时间太多。 我在通过Breeze.js进行的Web API调用中将Excel文件作为响应types发送时遇到问题。 有没有办法做到这一点应该是一个快速的方式,因为它也可能需要在移动设备上? 编辑 下面是我写的代码 – 用于绑定的JavaScript代码 – function exportListToExcel() { DataContext.exportListToExcel().then(function (data) { //Do some stuff. }); } 在微风中实现的数据上下文中,代码正在返回诺言 – function exportListToExcel() { function querySucceeded() { //return data; } return util.sendRequest(config.baseApiPath + 'breeze/MyController/ExportListToExcel') .then(querySucceeded) .fail(queryFailed); } 下面的代码是发送到Web API的请求。 我不知道是否应该是HttpPost或其他东西。 [HttpPost] public HttpResponseMessage ExportListToExcel() { return ExportListToExcel(); } […]

在Web应用程序中集成的Excel工作簿上进行协作

在我的公司,我们使用excel很多,而且我一直在使用VBA编写excelmacros来自动化任何可以自动化的东西,最近我们需要在一些表单上进行协作,并且我们使用了google表单。 然后,我编写了一个脚本,在被某人编辑时自动保护单元格,并使其成为唯一允许的编辑器,并在完成时使用button清除保护。 (+为谷歌) 我们宁愿使用Excel,所以我发现可以托pipe一个Web应用程序并使用JavaScript API将Excel工作表与自定义HTML和CSS一起embedded,可以在这里find一个示例(不支持在线支持VBA) 是否可以将Excel工作表embedded到托pipe的Web应用程序中,然后允许不同的用户在Web应用程序内进行协作,然后在编辑时自动保护单元格,并使其编辑器成为唯一允许编辑的单元格,然后将设置保存到下一个会议? 通过使用例如Web应用程序用户目录或Microsoft Exchange Server进行身份validation。

从Excel VSTO WorkBook中调用Azure AD保护的WebApi

我正尝试从Excel VSTO WorkBook中调用受Azure AD保护的WebApi。 这是我们用于我们的SPA应用程序相同的webApi,但现在也想直接从Excel中使用这个相同的API。 我已经search了一段时间,找不到任何指导如何工作。 有谁知道这是否可能,如果是的话应该如何实现?

使用webapi和angularjs下载excel文件

我试图在webapi / angularjs应用程序中下载一个closedXml excel文件。 我使用以下命令从服务器上的webapi控制器返回数据: HttpResponseMessage result = new HttpResponseMessage(); result = Request.CreateResponse(HttpStatusCode.OK); MemoryStream stream = GetStream(workbook); result.Content = new StreamContent(stream); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.ms-excel"); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "Download.xlsx" }; return result; 然后使用以下命令将其保存在客户端上: $scope.openExcel = function (data, status, headers, deferred) { var type = headers('Content-Type'); var disposition = headers('Content-Disposition'); if (disposition) […]

ASP.NET WebApi无法在Azure中使用COM(Excel)

COM对象有一些问题 我有一个Web API控制器,创build和保存Excel文件。 Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); excel.Workbooks.Add(); Microsoft.Office.Interop.Excel._Worksheet workSheet = excel.ActiveSheet; try { workSheet.Cells[1, "A"] = "Id"; -//- int row = 2; foreach (var _c in db.Clients) { workSheet.Cells[row, "A"] = _c.ClientId; -//- row++; } workSheet.Range["A1"].AutoFormat(Microsoft.Office.Interop.Excel.XlRangeAutoFormat.xlRangeAutoFormatClassic1); fileName = string.Format(@"{0}/ExcelData.xlsx", System.Web.HttpContext.Current.Server.MapPath("~/Reports")); workSheet.SaveAs(fileName); 在创build之后,控制器为这个文件返回一个url。 在我的本地主机上,它工作得非常好,但作为主机部署到Azure云后,我有一个例外: ExceptionMessage: "Retrieving the COM class factory for component with CLSID […]

Excel PowerQuery / C#WebAPI OData,检索旧的服务参考

尝试将Excel Power Query连接到我的OData Web服务时出现一些奇怪的行为。 当我开始构buildWeb服务时,我的基础数据类(POCO)被称为“FilterSearchFacade”。 随着开发的继续,我将基础数据类重新命名为“ReportSource”。 当我通过Web浏览器使用URL连接到Web服务时,返回正确的“ReportSource”对象。 但是,当我连接PowerQuery时,它返回以下错误: 就像在Excel中有一些数据caching保留在旧的类定义中一样? 我努力了… *在Excel中进入“Power Query”>“Recent Sources”,将其全部删除并重新启动excel。 *在我的WebAPI项目中search类名“FilterSearchFacade”的全部代码,没有。 *从WebAPI项目中删除bin / obj文件夹,清理和重build。 当我从Web浏览器转到项目的元数据根目录时,它显示了正确的类定义: 本地debugging: http://localhost:61023/api/PortlandDev/2/$metadata <edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0"> <edmx:DataServices> <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Sulzer.STAT.DataService"> <EntityType Name="ReportSource"> <Key>… 我被困在这里 OData项目没有对“FilterSearchFacade”类的引用,但Excel仍在尝试引用该types。 任何有关额外项目的想法或如何进行将非常感激。

我们可以使用epplus库创build带有checkbox选项的下拉列表

初始化工作表: public HttpResponseMessage ER_GenerateWBLWorksheet2() { ExcelPackage ExclPkg = new ExcelPackage(); ExcelWorksheet wsSheet1 = ExclPkg.Workbook.Worksheets.Add("Sheet1"); wsSheet1.Cells["A1"].Value = "ProductName"; wsSheet1.Cells["B1"].Value = "Price"; wsSheet1.Cells["C1"].Value = "ProductImageUrl"; wsSheet1.Cells["D1"].Value = "ProductUrl"; wsSheet1.Cells["E1"].Value = "StoreId"; wsSheet1.Cells["G1"].Value = "CategoryId"; wsSheet1.Cells["I1"].Value = "ColorId"; wsSheet1.Cells["K1"].Value = "FabricId"; wsSheet1.Cells["M1"].Value = "Gender"; 创build类别列表: var categorylist = wsSheet1.DataValidations.AddListValidation(wsSheet1.Cells["G2:G500"].Address); var categories = _categoryServices.GetAllCategory(); var categoryEntities = (categories != […]

如何使用webapi读取本地excel文件?

public class ExcelParserController : ApiController { [HttpGet] public IEnumerable<string> Get(string templatePath) { ExcelParser excelParser = new ExcelParser(); return excelParser.Parse(templatePath); } } 这是我的第一个想法。但是,我不知道如何从服务器读取本地excel文件。 templatePath就像“C:\ 1.xlsx”。如何使用webapi打开本地文件? 先进的感谢!

使用WebAPI / MVC下载Excel文件

我正试图通过WebAPI下载Excel文件。 基本上Excel文件是通过记忆stream在这篇文章的帮助下创build的 Excel Content正在生成,但是我无法下载Excel,因为当我在Chrome Network Tools的“响应”选项卡中看到响应时,响应本身就是纯XML。 以下是我的代码为C# var sheet = linq.ExportToExcel(userAddedList); var stream = new MemoryStream(); var sw = new StreamWriter(stream); sw.Write(sheet); sw.Flush(); var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(stream.GetBuffer()) }; result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "Report.xml" }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/ms-excel"); var response = ResponseMessage(result); return response; 这就是我如何通过Angular调用它。 var […]