Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #r "DocumentFormat.OpenXml.dll"
- #r "WindowsBase.dll"
- using System.Net;
- using System.IO;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml.Spreadsheet;
- public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log)
- {
- log.Info($"C# HTTP trigger function processed a request. RequestUri={req.RequestUri}");
- WebClient client = new WebClient();
- byte[] buffer = client.DownloadData("http://amor-webapp-test.azurewebsites.net/Content/hello.xlsx");
- MemoryStream stream = new MemoryStream();
- stream.Write(buffer, 0, buffer.Length);
- stream.Position = 0;
- using (SpreadsheetDocument doc = SpreadsheetDocument.Open(stream, false))
- {
- WorkbookPart workbookPart = doc.WorkbookPart;
- SharedStringTablePart sstpart = workbookPart.GetPartsOfType<SharedStringTablePart>().First();
- SharedStringTable sst = sstpart.SharedStringTable;
- WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
- Worksheet sheet = worksheetPart.Worksheet;
- var cells = sheet.Descendants<Cell>();
- var rows = sheet.Descendants<Row>();
- log.Info(string.Format("Row count = {0}", rows.LongCount()));
- log.Info(string.Format("Cell count = {0}", cells.LongCount()));
- // One way: go through each cell in the sheet
- foreach (Cell cell in cells)
- {
- if ((cell.DataType != null) && (cell.DataType == CellValues.SharedString))
- {
- int ssid = int.Parse(cell.CellValue.Text);
- string str = sst.ChildElements[ssid].InnerText;
- log.Info(string.Format("Shared string {0}: {1}", ssid, str));
- }
- else if (cell.CellValue != null)
- {
- log.Info(string.Format("Cell contents: {0}", cell.CellValue.Text));
- }
- }
- }
- return req.CreateResponse(HttpStatusCode.OK, "Hello ");
- }
- #r "Excel.dll"
- #r "System.Data"
- using System.Net;
- using System.IO;
- using Excel;
- using System.Data;
- public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log)
- {
- log.Info($"C# HTTP trigger function processed a request. RequestUri={req.RequestUri}");
- WebClient client = new WebClient();
- byte[] buffer = client.DownloadData("http://amor-webapp-test.azurewebsites.net/Content/abcdefg.xls");
- MemoryStream stream = new MemoryStream();
- stream.Write(buffer, 0, buffer.Length);
- stream.Position = 0;
- IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
- DataSet result = excelReader.AsDataSet();
- for (int i = 0; i < result.Tables.Count; i++)
- {
- log.Info(result.Tables[i].TableName +" has " + result.Tables[i].Rows.Count + " rows.");
- }
- return req.CreateResponse(HttpStatusCode.OK, "Hello ");
- }
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(originalExcelUrl);
- using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
- using (Stream stream = response.GetResponseStream())
- {
- var doc = SpreadsheetDocument.Open(stream, true);
- // etc
- }
Add Comment
Please, Sign In to add comment