Ejemplo n.º 1
0
        private void ExportToExcel_click(object sender, RoutedEventArgs e)
        {
            //czy lista zawieta dane
            if (rows == null || rows.Count == 0)
            {
                MessageBox.Show("Brak danych do zapisania", "Zapis", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            //posortuj liste
            List <ExcelContent> OrderedRows = rows.OrderBy(x => x.ProductName).ToList();

            //wywołaj eksport
            MmMakerExporter exporter    = new MmMakerExporter(new FileStream("scalone.xls", FileMode.Create, FileAccess.Write));
            bool            writeStatus = exporter.ExportToExcel(OrderedRows);

            //pokaż komunikat
            if (writeStatus)
            {
                MessageBox.Show("Zapis zakończony!", "Zapis", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show("Niepowodzenie eksportu", "Zapis", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage ExportToExcel(List <ExcelContent> content)
        {
            if (content == null)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Dane do zasilenia pliku są wymagane."));
            }

            MemoryStream    stream   = new MemoryStream();
            MmMakerExporter exporter = new MmMakerExporter(stream);

            bool status = exporter.ExportToExcel(content);

            if (status == false)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Nie udało się wygenerować pliku XLS"));
            }

            stream.Position = 0;

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StreamContent(stream);
            response.Content.Headers.ContentDisposition          = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
            response.Content.Headers.ContentDisposition.FileName = "Scalone.xls";
            response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");

            return(response);
        }