protected void btnExport_Click(object sender, EventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"SupplierName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"Price"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"Gift"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"IsOrder"), typeof(string))); List <OfferUI> coll = OfferController.GetAllOfferByBidIdWithIsOrder(BidId); foreach (OfferUI offer in coll) { int i = 0; System.Data.DataRow row = dt.NewRow(); row[i++] = offer.SupplierName; row[i++] = offer.TotalPrice; row[i++] = offer.Gift; row[i++] = GlobalStrings.GetYesNo(offer.IsOrder); dt.Rows.Add(row); } SpreadsheetWriter ex = SpreadsheetWriter.FromDataTable(dt, false, true); Response.Clear(); Response.AddHeader(@"content-disposition", @"attachment;filename=OffersExport_" + DateTime.UtcNow.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension); Response.Charset = @"UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = ex.FileContentType; Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble()); Response.Write(ex.ToString()); Response.End(); }
protected void btnExport_Click(object sender, EventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(new System.Data.DataColumn(FiltersStrings.GetText(@"FilterName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(FiltersStrings.GetText(@"SubFilterName"), typeof(string))); List <FilterUI> filters = ProductController.GetAllFilter(); foreach (FilterUI filter in filters) { int i = 0; System.Data.DataRow row = dt.NewRow(); row[i++] = filter.FilterName; row[i++] = ProductController.ConvertSubFilterListToString(filter.LstSubFilter); dt.Rows.Add(row); } SpreadsheetWriter ex = SpreadsheetWriter.FromDataTable(dt, true, true); Response.Clear(); Response.AddHeader(@"content-disposition", @"attachment;filename=AppUsersExport_" + DateTime.UtcNow.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension); Response.Charset = @"UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = ex.FileContentType; Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble()); Response.Write(ex.ToString()); Response.End(); }
protected async override void OnExecute(object parameter) { try { if (parameter is ListBoxItemViewModel viewModel && viewModel.Target is ITableItem tableItem) { if (viewModel is IInfoProvider provider) { var props = provider.Info; var revision = (long)props["Revision"]; var tableName = await tableItem.Dispatcher.InvokeAsync(() => tableItem.Name); var dialog = new CommonSaveFileDialog(); dialog.Filters.Add(new CommonFileDialogFilter("excel file", "*.xlsx")); dialog.DefaultFileName = $"{tableName}_{revision}"; dialog.DefaultExtension = "xlsx"; if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { var dataSet = await tableItem.Dispatcher.InvokeAsync(() => tableItem.GetDataSet(this.authenticator, revision)); var writer = new SpreadsheetWriter(dataSet); writer.Write(dialog.FileName); AppMessageBox.Show(Resources.Message_Exported); } } } } catch (Exception e) { AppMessageBox.ShowError(e); } }
public async Task <IActionResult> DownloadProductionDataAsync(ProductionSheetData productiondata) { if (productiondata == null) { throw new ArgumentNullException(nameof(productiondata)); } else { string fileName = Path.GetTempFileName(); var data = productionDataSheetWriter.GenerateExcelSheet(productiondata); SpreadsheetWriter.Write(fileName, data); var memory = new MemoryStream(); using (var fileStream = new FileStream(fileName, FileMode.Open)) { await fileStream.CopyToAsync(memory); } memory.Position = 0; Response.Headers.Add("Content-Disposition", "attachment; filename=ExcelFile.xlsx"); return(File(memory, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")); } }
protected async override void OnExecute(object parameter) { try { if (parameter is ISelector selector && selector.SelectedItem is ListBoxItemViewModel viewModel && viewModel.Target is IDataBase dataBase) { if (viewModel is IInfoProvider provider) { var props = provider.Info; var revision = (string)props["Revision"]; var dataBaseName = await dataBase.Dispatcher.InvokeAsync(() => dataBase.Name); var dialog = new CommonSaveFileDialog(); dialog.Filters.Add(new CommonFileDialogFilter("excel file", "*.xlsx")); dialog.DefaultFileName = $"{dataBaseName}_{revision}"; dialog.DefaultExtension = "xlsx"; if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { var dataSet = await dataBase.GetDataSetAsync(this.authenticator, CremaDataSetFilter.Default, revision); var writer = new SpreadsheetWriter(dataSet); writer.Write(dialog.FileName); await AppMessageBox.ShowErrorAsync(Resources.Message_Exported); } } } } catch (Exception e) { await AppMessageBox.ShowErrorAsync(e); } }
protected void btnExport_Click(object sender, EventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(new System.Data.DataColumn(SupplierProfileStrings.GetText(@"OrderId"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SupplierProfileStrings.GetText(@"OrderDate"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SupplierProfileStrings.GetText(@"BidId"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SupplierProfileStrings.GetText(@"TotalPrice"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SupplierProfileStrings.GetText(@"ApprovedDeal"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SupplierProfileStrings.GetText(@"DealDetails"), typeof(string))); int year = Convert.ToInt32(ddlyear.SelectedValue); int month = Convert.ToInt32(ddlMonth.SelectedValue); int from = Convert.ToInt32(ddlDayFrom.SelectedValue); int to = Convert.ToInt32(ddlDayTo.SelectedValue); DateTime?start = null; DateTime?end = null; if (year != 0 && month != 0 && from != 0) { start = new DateTime(year, month, from); end = (to != 0 ? new DateTime(year, month, to) : end = new DateTime(year, month, DateTime.DaysInMonth(year, month))); } else if (year != 0 && month != 0) { start = new DateTime(year, month, 1); end = new DateTime(year, month, DateTime.DaysInMonth(year, month)); } else if (year != 0) { start = new DateTime(year, 1, 1); end = new DateTime(year, 12, 31); } List <OrderUI> orders = OrderController.GetOrderSupplierHistoryExcel(SuppliersSessionHelper.SupplierId(), start, end); foreach (OrderUI order in orders) { int i = 0; System.Data.DataRow row = dt.NewRow(); row[i++] = order.OrderId; row[i++] = order.OrderDate; row[i++] = order.BidId; row[i++] = order.Price; row[i++] = GlobalStrings.GetYesNo(order.IsPayed); row[i++] = ListTostring(order.LstProduct); dt.Rows.Add(row); } SpreadsheetWriter ex = SpreadsheetWriter.FromDataTable(dt, true, true); Response.Clear(); Response.AddHeader(@"content-disposition", @"attachment;filename=Deals_" + DateTime.UtcNow.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension); Response.Charset = @"UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = ex.FileContentType; Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble()); Response.Write(ex.ToString()); Response.End(); }
protected void btnExport_Click(object sender, EventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"ProductName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"ProductCode"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"Amount"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"RecomendedPrice"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"Description"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"AnimalType"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"ProductPrice"), typeof(string))); //dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"Category"), typeof(string))); // dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"SubCategory"), typeof(string))); // dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"ProductRate"), typeof(string))); string searchCode = "%" + txtSearch.Text.Trim() + "%"; List <ProductUI> products = ProductController.GetAllProductUI(searchCode, Int64.Parse(ddlCategory.SelectedValue), Int64.Parse(ddlSubCategory.SelectedValue)); foreach (ProductUI product in products) { int i = 0; System.Data.DataRow row = dt.NewRow(); row[i++] = product.ProductName; row[i++] = product.ProductCode; row[i++] = product.Amount; row[i++] = product.RecomendedPrice; row[i++] = product.Description; row[i++] = ProductController.ConvertListToString(product.AnimalLst); SupplierProduct sup_prd = SupplierProduct.FetchByID(SuppliersSessionHelper.SupplierId(), product.ProductId); if (sup_prd != null) { row[i++] = sup_prd.Price; } //row[i++] = product.CategoryName; // row[i++] = product.SubCategoryName; // row[i++] = product.ProductRate; dt.Rows.Add(row); } SpreadsheetWriter ex = SpreadsheetWriter.FromDataTable(dt, false, true); Response.Clear(); Response.AddHeader(@"content-disposition", @"attachment;filename=ProductsExport_" + DateTime.UtcNow.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension); Response.Charset = @"UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = ex.FileContentType; Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble()); Response.Write(ex.ToString()); Response.End(); }
protected void btnExport_Click(object sender, EventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(new System.Data.DataColumn(AppUsersStrings.GetText(@"Email"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(AppUsersStrings.GetText(@"FirstName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(AppUsersStrings.GetText(@"LastName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(AppUsersStrings.GetText(@"IsLocked"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(AppUsersStrings.GetText(@"Phone"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(AppUsersStrings.GetText(@"Address"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(AppUsersStrings.GetText(@"IsAdv"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(AppUsersStrings.GetText(@"LastLogin"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(AppUsersStrings.GetText(@"CreateDate"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(AppUsersStrings.GetText(@"UserId"), typeof(string))); string searchName = "%" + txtSearchName.Text.Trim() + "%"; string searchPhone = "%" + txtSearchPhone.Text.Trim() + "%"; DateTime from, to = new DateTime(); DateTime.TryParse(dpSearchCreateDateFrom.Value.ToString(), out from); DateTime.TryParse(dpSearchCreateDateTo.Value.ToString(), out to); List <AppUserUI> app_users = AppUserUI.GetAllAppUserUI(from, to, searchName, searchPhone); foreach (AppUserUI appUser in app_users) { System.Data.DataRow row = dt.NewRow(); row[0] = appUser.Email; row[1] = appUser.FirstName; row[2] = appUser.LastName; row[3] = GlobalStrings.GetYesNo(appUser.IsLocked); row[4] = "\"" + appUser.Phone + "\""; row[5] = appUser.Street + " " + appUser.HouseNum + "\n" + AppUsersStrings.GetText(@"Floor") + " " + appUser.Floor + "\n" + AppUsersStrings.GetText(@"ApartmentNumber") + " " + appUser.ApartmentNumber + "\n" + appUser.CityName; row[6] = GlobalStrings.GetYesNo(appUser.IsAdv); row[7] = "\"" + appUser.LastLogin + "\""; row[8] = "\"" + appUser.CreateDate + "\""; row[9] = "\"" + appUser.AppUserId + "\""; dt.Rows.Add(row); } SpreadsheetWriter ex = SpreadsheetWriter.FromDataTable(dt, false, true); Response.Clear(); Response.AddHeader(@"content-disposition", @"attachment;filename=AppUsersExport_" + DateTime.UtcNow.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension); Response.Charset = @"UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = ex.FileContentType; Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble()); Response.Write(ex.ToString()); Response.End(); }
public ExcelWriter(string firstSheetName) : this() { var sheet = _doc.WorkbookPart.Workbook.Descendants <Sheet>().First(s => s.Name == "Sheet1"); if (sheet != null) { sheet.Name = firstSheetName; } SpreadsheetWriter.RemoveWorksheet(_doc, "Sheet2"); SpreadsheetWriter.RemoveWorksheet(_doc, "Sheet3"); }
public string GetResult(int columnCount, params object[] values) { using (var stream = new MemoryStream()) { using (var writer = new SpreadsheetWriter(stream)) { writer.WriteSpreedsheat(new SpreadsheetProcessingResult(columnCount, values)); stream.Position = 0; return(Encoding.UTF8.GetString(stream.ToArray())); } } }
protected void btnExportForCRM_Click(object sender, EventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"SupplierId"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"BusinessName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"SupplierServices"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(AppUsersStrings.GetText(@"Address"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"CityName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"Phone"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"ContactPhone"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"ContactName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"Email"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"SupplierType"), typeof(string))); List <SupplierUI> suppliers = new List <SupplierUI>(); string searchName = "%" + txtSearchName.Text.Trim() + "%"; string searchPhone = "%" + txtSearchPhone.Text.Trim() + "%"; suppliers = SupplierController.GetAllSuppliersUI(true, searchName, searchPhone); foreach (SupplierUI supplier in suppliers) { int i = 0; System.Data.DataRow row = dt.NewRow(); row[i++] = supplier.SupplierId; row[i++] = supplier.BusinessName; row[i++] = getSupplierServices(supplier); row[i++] = supplier.Street + " " + supplier.HouseNum; row[i++] = supplier.CityName; row[i++] = "=\"" + supplier.Phone + "\""; row[i++] = "=\"" + supplier.ContactPhone + "\""; row[i++] = supplier.ContactName; row[i++] = supplier.Email; row[i++] = supplier.IsProduct ? SuppliersStrings.GetText(@"IsProduct") : SuppliersStrings.GetText(@"IsService"); dt.Rows.Add(row); } System.Data.DataRow sumRow = dt.NewRow(); sumRow[0] = SuppliersStrings.GetText(@"SumSumPerMonth") + " " + suppliers.Sum(o => o.SumPerMonth); dt.Rows.Add(sumRow); SpreadsheetWriter ex = SpreadsheetWriter.FromDataTable(dt, false, true); Response.Clear(); Response.AddHeader(@"content-disposition", @"attachment;filename=SuppliersExportForCRM_" + DateTime.UtcNow.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension); Response.Charset = @"UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = ex.FileContentType; Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble()); Response.Write(ex.ToString()); Response.End(); }
protected void btnExport_Click(object sender, EventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"SupplierId"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"BusinessName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"Phone"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"ContactName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"ContactPhone"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"CityName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SupplierEventStrings.GetText(@"ClickNum"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(SupplierEventStrings.GetText(@"ClickToCallNum"), typeof(string))); List <SupplierServiceUI> suppliers = new List <SupplierServiceUI>(); string searchName = txtSearchName.Text.Trim(); string searchPhone = txtSearchPhone.Text.Trim(); string searchId = txtSearchSupplierId.Text.Trim(); string searchCity = txtSearchCity.Text.Trim(); DateTime from, to = new DateTime(); DateTime.TryParse(datepickerFrom.Text.ToString(), out from); DateTime.TryParse(datepickerTo.Text.ToString(), out to); suppliers = ServiceController.GetServiceSuppliersAndNumEvents(searchName, searchPhone, searchId, searchCity, from, to, true); foreach (SupplierServiceUI supplier in suppliers) { System.Data.DataRow row = dt.NewRow(); row[0] = supplier.SupplierId; row[1] = supplier.BusinessName; row[2] = "\"" + supplier.Phone + "\""; row[3] = supplier.ContactName; row[4] = "\"" + supplier.ContactPhone + "\""; row[5] = supplier.CityName; row[6] = supplier.ClickNum; row[7] = supplier.ClickToCallNum; dt.Rows.Add(row); } //System.Data.DataRow sumRow = dt.NewRow(); //sumRow[0] = SuppliersStrings.GetText(@"SumSumPerMonth") + " " + suppliers.Sum(o => o.SumPerMonth); //dt.Rows.Add(sumRow); SpreadsheetWriter ex = SpreadsheetWriter.FromDataTable(dt, false, true); Response.Clear(); Response.AddHeader(@"content-disposition", @"attachment;filename=ServiceSuppliersReport_" + DateTime.UtcNow.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension); Response.Charset = @"UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = ex.FileContentType; Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble()); Response.Write(ex.ToString()); Response.End(); }
/// <summary> /// 将查询出的DataSet导出为Excel。 /// </summary> /// <param name="dataSet">要导出的DataSet数据集,可以包含多个DataTable数据,使用DataSetName作为导出的文件名</param> public static void ExportDataSet(DataSet dataSet) { if (dataSet == null) { throw new ArgumentException("dataSet"); } if (dataSet.Tables.Count == 0) { return; } MemoryStream stream = SpreadsheetReader.Create(); SpreadsheetDocument doc = SpreadsheetDocument.Open(stream, true); //首先清空原有的Sheet var allSheet = doc.WorkbookPart.Workbook.Descendants <Sheet>(); if (allSheet.Count() > 0) { doc.WorkbookPart.Workbook.Sheets.RemoveAllChildren(); } //构造Excel foreach (DataTable dt in dataSet.Tables) { WorksheetPart sheetPart = SpreadsheetWriter.InsertWorksheet(doc, dt.TableName); WorksheetWriter sheetWriter = new WorksheetWriter(doc, sheetPart); //打印列名 int colIndex = 0;//当前第几列,从0开始 foreach (DataColumn col in dt.Columns) { string reference = GetExcelColumnHeader(colIndex) + "1"; sheetWriter.PasteText(reference, col.ColumnName); colIndex++; } sheetWriter.PasteDataTable(dt, "A2"); SpreadsheetWriter.Save(doc); } //Write to response stream System.Web.HttpContext context = System.Web.HttpContext.Current; context.Response.Clear(); string UserAgent = context.Request.ServerVariables["http_user_agent"].ToLower(); string FileName = dataSet.DataSetName; if (UserAgent.IndexOf("firefox") == -1) {//非火狐浏览器 FileName = context.Server.UrlEncode(FileName); } context.Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", FileName + ".xlsx")); context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; stream.WriteTo(context.Response.OutputStream); context.Response.End(); }
protected void btnExport_Click(object sender, EventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"BidId"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"StartDate"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"EndDate"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"OffersCount"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"Products"), typeof(string))); if (bidType != BidType.BidCount || bidType != BidType.BidPurchase) { dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"OrderDate"), typeof(string))); } List <BidUI> coll; if (AllBids) { coll = BidController.GetAllBidByCustomerTypeAndBidType(customerType, bidType, BidLeave, 0, 0); } else { coll = BidController.GetAllBidByCustomerIdAndBidType(CustomerId, customerType, bidType, 0, 0); } foreach (BidUI Bid in coll) { int i = 0; System.Data.DataRow row = dt.NewRow(); row[i++] = Bid.BidId; row[i++] = "\"" + Bid.StartDate + "\""; row[i++] = "\"" + Bid.EndDate + "\""; row[i++] = Bid.OfferNum; row[i++] = Bid.Products.Replace("<br>", ","); if (bidType != BidType.BidCount || bidType != BidType.BidPurchase) { row[i++] = "\"" + Bid.OrderDate + "\""; } dt.Rows.Add(row); } SpreadsheetWriter ex = SpreadsheetWriter.FromDataTable(dt, false, true); Response.Clear(); Response.AddHeader(@"content-disposition", @"attachment;filename=MyBidsExport_" + DateTime.UtcNow.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension); Response.Charset = @"UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = ex.FileContentType; Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble()); Response.Write(ex.ToString()); Response.End(); }
private static string Evaluate(string data) { using (var reader = new SpreadsheetReader(new StringReader(data))) { using (var ms = new MemoryStream()) { using (var writer = new SpreadsheetWriter(ms)) { writer.WriteSpreedsheat(new SpreadsheetProcessor(reader.ReadSpreadsheet()).Evaluate(new ParallelProcessingStrategy())); return(Encoding.UTF8.GetString(ms.ToArray())); } } } }
protected void ExportToExcel(int limit, int offset) { EmailLogCollection coll = EmailLogController.GetLogItems(EmailLog.Columns.DeliveryDate, dg.Sql.SortDirection.DESC, limit, offset); System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(new System.Data.DataColumn(EmailTemplatesStrings.GetText("LogNumber"), typeof(Int64))); dt.Columns.Add(new System.Data.DataColumn(GlobalStrings.GetText("Date"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(GlobalStrings.GetText("Status"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(EmailTemplatesStrings.GetText("Subject"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(EmailTemplatesStrings.GetText("From"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(EmailTemplatesStrings.GetText("Recipient"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(EmailTemplatesStrings.GetText("CC"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(EmailTemplatesStrings.GetText("BCC"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(EmailTemplatesStrings.GetText("Priority"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(EmailTemplatesStrings.GetText("Content"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(EmailTemplatesStrings.GetText("Exception"), typeof(string))); foreach (EmailLog item in coll) { System.Data.DataRow row = dt.NewRow(); row[0] = item.EmailLogId; row[1] = item.DeliveryDate.ToString(@"dd/MM/yyyy HH:mm:ss"); row[2] = GetStatus(item.Status); row[3] = item.Subject; row[4] = item.FromEmail + (string.IsNullOrEmpty(item.FromName) ? string.Empty : @" - " + item.FromName); row[5] = item.ToList; row[6] = item.CcList; row[7] = item.BccList; row[8] = GetMailPriority(item.MailPriority); row[9] = item.Body.Replace(@"<br />", "\r\n").StripHtml(); row[10] = item.Exception; dt.Rows.Add(row); } SpreadsheetWriter ex = SpreadsheetWriter.FromDataTable(dt, true, true); Response.Clear(); Response.AddHeader(@"content-disposition", @"attachment;filename=EmailLogsExport_" + DateTime.UtcNow.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension); Response.Charset = @"UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = ex.FileContentType; Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble()); Response.Write(ex.ToString()); Response.End(); }
/// <summary> /// Create the spreadsheet. /// </summary> /// <param name="documentName">Excel file name.</param> /// <param name="excelWorkSheetName">Excel worksheet name: default: sheet1.</param> /// <param name="rowData">Row data to write.</param> /// <param name="headerData">Header data.</param> /// <param name="rowPointers">Row pointers.</param> /// <param name="styleSheet">Style sheet.</param> /// <returns>Memory stream.</returns> private static MemoryStream CreateSpreadSheet(string documentName, string excelWorkSheetName, IEnumerable <T> rowData, string[] headerData, string[] rowPointers, Stylesheet styleSheet) { int rowNum = 0; int colNum = 0; int maxWidth = 0; int minCol = 1; int maxCol = rowPointers == null ? minCol : rowPointers.Length; maxCol = maxCol == 1 && headerData == null ? 1 : headerData.Length; MemoryStream xmlStream = SpreadsheetReader.Create(); SpreadsheetDocument spreadSheet = SpreadsheetDocument.Open(xmlStream, true); SetSheetName(excelWorkSheetName, spreadSheet); if (styleSheet == null) { SetStyleSheet(spreadSheet); } else { spreadSheet.WorkbookPart.WorkbookStylesPart.Stylesheet = styleSheet; spreadSheet.WorkbookPart.WorkbookStylesPart.Stylesheet.Save(); } WorksheetPart worksheetPart = SpreadsheetReader.GetWorksheetPartByName(spreadSheet, excelWorkSheetName); WriteHeaders(headerData, out rowNum, out colNum, out maxWidth, spreadSheet, worksheetPart); AddCellWidthStyles(Convert.ToUInt32(minCol), Convert.ToUInt32(maxCol), maxWidth, spreadSheet, worksheetPart); if (rowPointers == null || rowPointers.Length == 0) { WriteRowsFromHeaders(rowData, headerData, rowNum, out maxWidth, spreadSheet, worksheetPart); } else { WriteRowsFromKeys(rowData, rowPointers, rowNum, out maxWidth, spreadSheet, worksheetPart); } // Save to the memory stream SpreadsheetWriter.Save(spreadSheet); spreadSheet.Close(); spreadSheet.Dispose(); return(xmlStream); }
protected void btnExport_Click(object sender, EventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(new System.Data.DataColumn(Yad2Strings.GetText(@"ProductName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(Yad2Strings.GetText(@"LstCategory"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(Yad2Strings.GetText(@"Price"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(Yad2Strings.GetText(@"CityName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(Yad2Strings.GetText(@"ContactName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(Yad2Strings.GetText(@"Phone"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(Yad2Strings.GetText(@"Details"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(Yad2Strings.GetText(@"Status"), typeof(string))); List <int> StatusIdList = FillStatusList(); List <ProductYad2UI> productsYad2 = ProductYad2Controller.GetAllProductsYad2(StatusIdList); foreach (ProductYad2UI product in productsYad2) { System.Data.DataRow row = dt.NewRow(); row[0] = product.ProductName; row[1] = (product.LstCategory.Count == 0 || product.LstCategory == null) ? "" : String.Join(", ", product.LstCategory.Select(p => p.CategoryYad2Name)); row[2] = product.Price; row[3] = product.CityName; row[4] = product.ContactName; row[5] = "\"" + product.Phone + "\""; row[6] = product.Details; row[7] = Yad2Strings.GetText(Enum.GetName(typeof(StatusType), product.Status)); dt.Rows.Add(row); } System.Data.DataRow sumRow = dt.NewRow(); sumRow[0] = Yad2Strings.GetText(@"SumPrice") + " " + productsYad2.Sum(p => p.Price); dt.Rows.Add(sumRow); SpreadsheetWriter ex = SpreadsheetWriter.FromDataTable(dt, false, true); Response.Clear(); Response.AddHeader(@"content-disposition", @"attachment;filename=ProductsYad2Export_" + DateTime.UtcNow.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension); Response.Charset = @"UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = ex.FileContentType; Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble()); Response.Write(ex.ToString()); Response.End(); }
public static MemoryStream CalcSpreadsheetDocument(MemoryStream ms, bool DeleteFormula, string OutFile) { bool pg = (progressBar != null); SpreadsheetDocument RecultDoc = SpreadsheetDocument.Open(ms, true); if (DeleteFormula) { RecultDoc.WorkbookPart.DeletePart(RecultDoc.WorkbookPart.CalculationChainPart); } foreach (Sheet curSheet in RecultDoc.WorkbookPart.Workbook.Sheets) { WorksheetPart RecultWorkSheetPart = SpreadsheetReader.GetWorksheetPartByName(RecultDoc, curSheet.Name.Value); IEnumerable <Row> ListRowInRange = RecultWorkSheetPart.Worksheet.Elements <SheetData>().First().Elements <Row>().Where(r => r.Elements <Cell>().Where(c => c.CellFormula != null).Count() > 0); if (pg) { progressBar.Maximum = ListRowInRange.Count(); } int value = 0; foreach (Row Row in ListRowInRange) { IEnumerable <Cell> fCell = Row.Elements <Cell>().Where(c => c.CellFormula != null).Where(c => c.CellFormula.Text.Trim() != ""); foreach (Cell c in fCell) { var dd = calcFormule(c, RecultWorkSheetPart, RecultDoc, DeleteFormula); } if (pg) { progressBar.Value = ++value; } } } RecultDoc.Close(); if (OutFile != null) { if (OutFile.Length > 0) { SpreadsheetWriter.StreamToFile(OutFile, ms); } } return(ms); }
public void Write(IEnumerable <IRow> rows) { foreach (var row in rows) { var cellDfns = new List <CellDfn>(); var rowDef = new RowDfn { Cells = cellDfns }; cellDfns.AddRange(_fields.Select(field => new CellDfn { CellDataType = field.ToCellDataType(), Value = field.Type == "guid" ? row[field].ToString() : row[field], FormatCode = field.Format.Replace("tt", "AM/PM") })); _rowDfns.Add(rowDef); } SpreadsheetWriter.Write(_fileInfo.FullName, _workbook); }
protected void btnExport_Click(object sender, EventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"BidId"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"StartDate"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"EndDate"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"TotalPrice"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"Products"), typeof(string))); if (Action == "Win" || Action == "Offers") { dt.Columns.Add(new System.Data.DataColumn(BidString.GetText(@"OrderDate1"), typeof(string))); } List <BidUI> coll = BidController.GetSupplierBids(SupplierId, Action, FromDate, ToDate, BidId); foreach (BidUI bid in coll) { int i = 0; System.Data.DataRow row = dt.NewRow(); row[i++] = bid.BidId; row[i++] = "\"" + bid.StartDate + "\""; row[i++] = "\"" + bid.EndDate + "\""; row[i++] = bid.Price; row[i++] = (bid.LstProduct.Count == 0 || bid.LstProduct == null) ? "" : String.Join(", ", bid.LstProduct.Select(o => o.ProductName)); if (Action == "Win" || Action == "Offers") { row[i++] = "\"" + bid.OrderDate + "\""; } dt.Rows.Add(row); } SpreadsheetWriter ex = SpreadsheetWriter.FromDataTable(dt, false, true); Response.Clear(); Response.AddHeader(@"content-disposition", @"attachment;filename=Supplier" + SupplierId + Action + "BidsExport_" + DateTime.UtcNow.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension); Response.Charset = @"UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = ex.FileContentType; Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble()); Response.Write(ex.ToString()); Response.End(); }
//Создание отчета public MemoryStream GenerateReport(DataSet dataSet, string Temleyt, string OutFile) { MemoryStream ms = new MemoryStream(); ms = SpreadsheetReader.Copy(Temleyt); SpreadsheetDocument RecultDoc = SpreadsheetDocument.Open(ms, true); MemoryStream tp = new MemoryStream(); tp = SpreadsheetReader.Copy(Temleyt); SpreadsheetDocument TemleytDoc = SpreadsheetDocument.Open(tp, true); foreach (Sheet curSheet in TemleytDoc.WorkbookPart.Workbook.Sheets) { UInt32 Offset = 0; // Получаем имена областей DefinedNames принадлежащих к текущему Sheet List <DefinedName> dn = RecultDoc.WorkbookPart.Workbook.Elements <DefinedNames>().First().Elements <DefinedName>() .Where(d => d.Text.IndexOf("#REF!") < 0 && curSheet.Name.Value == d.Text.Substring(0, d.Text.IndexOf("!")).TrimEnd('\'').TrimStart('\'')).ToList(); foreach (DefinedName definedName in dn) { DataTable dataTable = GetTableByName(dataSet, definedName.Name); if (dataTable != null) { Offset = SetValueFromDataTable(dataTable, RecultDoc, TemleytDoc, Offset); } } } SetValueWithoutRange(dataSet, RecultDoc); ClearSpreadsheetDocument(RecultDoc); TemleytDoc.Close(); RecultDoc.Close(); if (OutFile != null) { if (OutFile.Length > 0) { SpreadsheetWriter.StreamToFile(OutFile, ms); } } return(ms); }
public void Export(string itemPath, CremaDataSet dataSet) { if (dataSet.Tables.Any() == false) { return; } var spreadsheetWriterSettings = new SpreadsheetWriterSettings() { OmitAttribute = this.settings.OmitAttribute, OmitSignatureDate = this.settings.OmitSignatureDate, }; var writer = new SpreadsheetWriter(dataSet, spreadsheetWriterSettings); var filename = this.OutputPath; if (this.settings.IsSeparable == true) { var outputPath = itemPath.Trim(PathUtility.SeparatorChar).Replace(PathUtility.SeparatorChar, '.'); if (outputPath == string.Empty) { outputPath = this.cremaAppHost.DataBaseName; } if (this.settings.IsIncludeDate) { //------------------------------------------------------ // TableName_2017-02-17_05_11.xlsx string szDate = DateTime.Now.ToString($"{this.settings.OutputDateFormat}"); filename = FileUtility.Prepare(this.outputPath, $"{outputPath}_{szDate}.xlsx"); } else { filename = FileUtility.Prepare(this.outputPath, outputPath + ".xlsx"); } } using (var stream = new FileStream(filename, FileMode.Create)) { writer.Write(stream); } this.configs.Commit(this.settings); this.configs.Commit(this); }
private void WriteTables(CremaDataSet dataSet, string filename) { var path = Path.Combine(this.CommandContext.BaseDirectory, filename); var settings = new SpreadsheetWriterSettings() { OmitAttribute = this.OmitAttribute, OmitSignatureDate = this.OmitSignatureDate, Tags = (TagInfo)TagsProperties.Tags, }; var progress = new ConsoleProgress(this.Out) { Style = ConsoleProgressStyle.None }; using (var writer = new SpreadsheetWriter(dataSet, settings)) { writer.Write(path, progress); } this.Out.WriteLine($"export: \"{path}\""); }
protected void btnExport_Click(object sender, EventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(new System.Data.DataColumn(CategoriesStrings.GetText(@"CategoryId"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(CategoriesStrings.GetText(@"CategoryName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(CategoriesStrings.GetText(@"CategoryRate"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(CategoriesStrings.GetText(@"SubCategoryId"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(CategoriesStrings.GetText(@"SubCategoryName"), typeof(string))); List <CategoryUI> categories = ProductController.GetAllCategoriesAndSubCategories(); foreach (CategoryUI category in categories) { int i = 0; System.Data.DataRow row = dt.NewRow(); row[i++] = category.CategoryId; row[i++] = category.CategoryName; row[i++] = category.CategoryRate; row[i++] = category.SubCategoryId; row[i++] = category.SubCategoryName; dt.Rows.Add(row); } SpreadsheetWriter ex = SpreadsheetWriter.FromDataTable(dt, true, true); ExcelSheetStyle _style = new ExcelSheetStyle(); _style.Alignment.Horizontal = HorizontalAlignment.Center; ex.AddStyle(_style); Response.Clear(); Response.AddHeader(@"content-disposition", @"attachment;filename=CategoriesExport_" + DateTime.Now.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension); Response.Charset = @"UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = ex.FileContentType; Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble()); Response.Write(ex.ToString()); Response.End(); }
public void ExportToExcel() { var dialog = new CommonSaveFileDialog(); dialog.Filters.Add(new CommonFileDialogFilter("excel file", "*.xlsx")); dialog.DefaultExtension = "xlsx"; if (dialog.ShowDialog() != CommonFileDialogResult.Ok) { return; } try { var dataTable = this.tableViewModel.Source.ExportTable2(); var writer = new SpreadsheetWriter(dataTable.DataSet); writer.Write(dialog.FileName); } catch (Exception e) { AppMessageBox.ShowError(e); } }
protected void btnExport_Click(object sender, EventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"ProductName"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"ProductCode"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"Amount"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"ProductPrice"), typeof(string))); dt.Columns.Add(new System.Data.DataColumn(ProductsStrings.GetText(@"Gift"), typeof(string))); List <ProductUI> products = ProductController.GetSupplierProducts(SupplierId); foreach (ProductUI product in products) { int i = 0; System.Data.DataRow row = dt.NewRow(); row[i++] = product.ProductName; row[i++] = product.ProductCode; row[i++] = product.Amount; row[i++] = product.ProductPrice; row[i++] = product.Gift; dt.Rows.Add(row); } SpreadsheetWriter ex = SpreadsheetWriter.FromDataTable(dt, true, true); Response.Clear(); Response.AddHeader(@"content-disposition", @"attachment;filename=SupplierProductsExport_" + DateTime.Now.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension); Response.Charset = @"UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = ex.FileContentType; Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble()); Response.Write(ex.ToString()); Response.End(); }
static void Main(string[] args) { var isConsoleInput = args.Length < 1; var isConsoleOutput = args.Length < 2; try { var input = isConsoleInput ? Console.OpenStandardInput() : File.Open(args[0], FileMode.Open); var output = isConsoleOutput ? Console.OpenStandardOutput() : File.Create(args[1]); using (var reader = new SpreadsheetReader(input)) { Console.WriteLine(isConsoleInput ? Resources.EnterTable : Resources.ReadingTable); var spreadsheet = reader.ReadSpreadsheet(); Console.WriteLine(Resources.Processing); var processor = new SpreadsheetProcessor(spreadsheet); var result = processor.Evaluate(new ParallelProcessingStrategy()); Console.WriteLine(isConsoleOutput ? Resources.ResultTable : Resources.WritingResult); using (var write = new SpreadsheetWriter(output)) { write.WriteSpreedsheat(result); } } } catch (Exception exception) { Console.WriteLine(exception.Message); } if (isConsoleOutput) { Console.Write(Resources.PressAnyKeyForExit); Console.ReadKey(); } }
private static void Main() { var n = DateTime.Now; var tempDi = new DirectoryInfo(string.Format("ExampleOutput-{0:00}-{1:00}-{2:00}-{3:00}{4:00}{5:00}", n.Year - 2000, n.Month, n.Day, n.Hour, n.Minute, n.Second)); tempDi.Create(); var wb = new WorkbookDfn { Worksheets = new WorksheetDfn[] { new WorksheetDfn { Name = "MyFirstSheet", ColumnHeadings = new CellDfn[] { new CellDfn { Value = "DataType", Bold = true, }, new CellDfn { Value = "Value", Bold = true, HorizontalCellAlignment = HorizontalCellAlignment.Right, }, }, Rows = new RowDfn[] { new RowDfn { Cells = new CellDfn[] { new CellDfn { CellDataType = CellDataType.String, Value = "Boolean", }, new CellDfn { CellDataType = CellDataType.Boolean, Value = true, }, } }, new RowDfn { Cells = new CellDfn[] { new CellDfn { CellDataType = CellDataType.String, Value = "Boolean", }, new CellDfn { CellDataType = CellDataType.Boolean, Value = false, }, } }, new RowDfn { Cells = new CellDfn[] { new CellDfn { CellDataType = CellDataType.String, Value = "String", }, new CellDfn { CellDataType = CellDataType.String, Value = "A String", HorizontalCellAlignment = HorizontalCellAlignment.Right, }, } }, new RowDfn { Cells = new CellDfn[] { new CellDfn { CellDataType = CellDataType.String, Value = "int", }, new CellDfn { CellDataType = CellDataType.Number, Value = 100, }, } }, new RowDfn { Cells = new CellDfn[] { new CellDfn { CellDataType = CellDataType.String, Value = "int?", }, new CellDfn { CellDataType = CellDataType.Number, Value = (int?)100, }, } }, new RowDfn { Cells = new CellDfn[] { new CellDfn { CellDataType = CellDataType.String, Value = "int? (is null)", }, new CellDfn { CellDataType = CellDataType.Number, Value = null, }, } }, new RowDfn { Cells = new CellDfn[] { new CellDfn { CellDataType = CellDataType.String, Value = "uint", }, new CellDfn { CellDataType = CellDataType.Number, Value = (uint)101, }, } }, new RowDfn { Cells = new CellDfn[] { new CellDfn { CellDataType = CellDataType.String, Value = "long", }, new CellDfn { CellDataType = CellDataType.Number, Value = long.MaxValue, }, } }, new RowDfn { Cells = new CellDfn[] { new CellDfn { CellDataType = CellDataType.String, Value = "float", }, new CellDfn { CellDataType = CellDataType.Number, Value = (float)123.45, }, } }, new RowDfn { Cells = new CellDfn[] { new CellDfn { CellDataType = CellDataType.String, Value = "double", }, new CellDfn { CellDataType = CellDataType.Number, Value = 123.45, }, } }, new RowDfn { Cells = new CellDfn[] { new CellDfn { CellDataType = CellDataType.String, Value = "decimal", }, new CellDfn { CellDataType = CellDataType.Number, Value = (decimal)123.45, }, } }, new RowDfn { Cells = new CellDfn[] { new CellDfn { CellDataType = CellDataType.Date, Value = new DateTime(2012, 1, 8), FormatCode = "mm-dd-yy", }, new CellDfn { CellDataType = CellDataType.Date, Value = new DateTime(2012, 1, 9), FormatCode = "mm-dd-yy", Bold = true, HorizontalCellAlignment = HorizontalCellAlignment.Center, }, } }, } } } }; SpreadsheetWriter.Write(Path.Combine(tempDi.FullName, "Test2.xlsx"), wb); }
static void Main(string[] args) { var n = DateTime.Now; var tempDi = new DirectoryInfo(string.Format("ExampleOutput-{0:00}-{1:00}-{2:00}-{3:00}{4:00}{5:00}", n.Year - 2000, n.Month, n.Day, n.Hour, n.Minute, n.Second)); tempDi.Create(); WorkbookDfn wb = new WorkbookDfn { Worksheets = new WorksheetDfn[] { new WorksheetDfn { Name = "MyFirstSheet", TableName = "NamesAndRates", ColumnHeadings = new CellDfn[] { new CellDfn { Value = "Name", Bold = true, }, new CellDfn { Value = "Age", Bold = true, HorizontalCellAlignment = HorizontalCellAlignment.Left, }, new CellDfn { Value = "Rate", Bold = true, HorizontalCellAlignment = HorizontalCellAlignment.Left, } }, Rows = new RowDfn[] { new RowDfn { Cells = new CellDfn[] { new CellDfn { CellDataType = CellDataType.String, Value = "Eric", }, new CellDfn { CellDataType = CellDataType.Number, Value = 50, }, new CellDfn { CellDataType = CellDataType.Number, Value = (decimal)45.00, FormatCode = "0.00", }, } }, new RowDfn { Cells = new CellDfn[] { new CellDfn { CellDataType = CellDataType.String, Value = "Bob", }, new CellDfn { CellDataType = CellDataType.Number, Value = 42, }, new CellDfn { CellDataType = CellDataType.Number, Value = (decimal)78.00, FormatCode = "0.00", }, } }, } } } }; SpreadsheetWriter.Write(Path.Combine(tempDi.FullName, "Test1.xlsx"), wb); }