protected void lnkBtnCreateWorkbook_Click(object sender, EventArgs e)
{
// get the Excel workbook format
ExcelWorkbookFormat workbookFormat = radioXlsFormat.Checked ? ExcelWorkbookFormat.Xls_2003 :
ExcelWorkbookFormat.Xlsx_2007;
// create the workbook in the desired format with a single worksheet
ExcelWorkbook workbook = new ExcelWorkbook(workbookFormat);
// set the license key before saving the workbook
workbook.LicenseKey = "RW51ZXZ0ZXVldGt1ZXZ0a3R3a3x8fHw=";
// set workbook description properties
workbook.DocumentProperties.Subject = "Data types and data formatting
demo";
workbook.DocumentProperties.Comments = "Add formatted data to an Excel
worksheet using Winnovative Excel library for .NET";
#region CREATE CUSTOM WORKBOOK STYLES
#region Add a style used for the cells in the worksheet title area
ExcelCellStyle titleStyle = workbook.Styles.AddStyle("WorksheetTitleStyle");
// center the text in the title area
titleStyle.Alignment.HorizontalAlignment = ExcelCellHorizontalAlignmentType.Center;
titleStyle.Alignment.VerticalAlignment = ExcelCellVerticalAlignmentType.Center;
// set the title area borders
titleStyle.Borders[ExcelCellBorderIndex.Bottom].Color = Color.Green;
titleStyle.Borders[ExcelCellBorderIndex.Bottom].LineStyle = ExcelCellLineStyle.Medium;
titleStyle.Borders[ExcelCellBorderIndex.Top].Color = Color.Green;
titleStyle.Borders[ExcelCellBorderIndex.Top].LineStyle = ExcelCellLineStyle.Medium;
titleStyle.Borders[ExcelCellBorderIndex.Left].Color = Color.Green;
titleStyle.Borders[ExcelCellBorderIndex.Left].LineStyle = ExcelCellLineStyle.Medium;
titleStyle.Borders[ExcelCellBorderIndex.Right].Color = Color.Green;
titleStyle.Borders[ExcelCellBorderIndex.Right].LineStyle = ExcelCellLineStyle.Medium;
if (workbookFormat == ExcelWorkbookFormat.Xls_2003)
{
// set the solid fill for the title area range with a custom color
titleStyle.Fill.FillType = ExcelCellFillType.SolidFill;
titleStyle.Fill.SolidFillOptions.BackColor = Color.FromArgb(255, 255, 204);
}
else
{
// set the gradient fill for the title area range with a custom color
titleStyle.Fill.FillType = ExcelCellFillType.GradientFill;
titleStyle.Fill.GradientFillOptions.Color1 = Color.FromArgb(255, 255, 204);
titleStyle.Fill.GradientFillOptions.Color2 = Color.White;
}
// set the title area font
titleStyle.Font.Size = 14;
titleStyle.Font.Bold = true;
titleStyle.Font.UnderlineType = ExcelCellUnderlineType.Single;
#endregion
#region Add a style used for text messages
ExcelCellStyle textMessageStyle = workbook.Styles.AddStyle("TextMessageStyle");
textMessageStyle.Font.Size = 10;
textMessageStyle.Font.Bold = true;
textMessageStyle.Alignment.VerticalAlignment = ExcelCellVerticalAlignmentType.Center;
textMessageStyle.Alignment.HorizontalAlignment = ExcelCellHorizontalAlignmentType.Left;
textMessageStyle.Fill.FillType = ExcelCellFillType.SolidFill;
textMessageStyle.Fill.SolidFillOptions.BackColor = Color.FromArgb(204, 255, 204);
textMessageStyle.Borders[ExcelCellBorderIndex.Bottom].LineStyle = ExcelCellLineStyle.Thin;
textMessageStyle.Borders[ExcelCellBorderIndex.Top].LineStyle = ExcelCellLineStyle.Thin;
textMessageStyle.Borders[ExcelCellBorderIndex.Left].LineStyle = ExcelCellLineStyle.Thin;
textMessageStyle.Borders[ExcelCellBorderIndex.Right].LineStyle = ExcelCellLineStyle.Thin;
#endregion
#region Add a style used for data validation ranges
ExcelCellStyle dataValidationStyle = workbook.Styles.AddStyle("DataValidationStyle");
dataValidationStyle.Font.Size = 10;
dataValidationStyle.Font.Bold = true;
dataValidationStyle.Alignment.VerticalAlignment = ExcelCellVerticalAlignmentType.Center;
dataValidationStyle.Fill.FillType = ExcelCellFillType.SolidFill;
dataValidationStyle.Fill.SolidFillOptions.BackColor = Color.FromArgb(153, 204, 0);
dataValidationStyle.Borders[ExcelCellBorderIndex.Bottom].LineStyle = ExcelCellLineStyle.Thin;
dataValidationStyle.Borders[ExcelCellBorderIndex.Top].LineStyle = ExcelCellLineStyle.Thin;
dataValidationStyle.Borders[ExcelCellBorderIndex.Left].LineStyle = ExcelCellLineStyle.Thin;
dataValidationStyle.Borders[ExcelCellBorderIndex.Right].LineStyle = ExcelCellLineStyle.Thin;
#endregion
#endregion
// get the first worksheet in the workbook
ExcelWorksheet worksheet = workbook.Worksheets[0];
// set the default worksheet name
worksheet.Name = "Data Types Demo";
#region WORKSHEET PAGE SETUP
// set worksheet paper size and orientation, margins, header and footer
worksheet.PageSetup.PaperSize = ExcelPagePaperSize.PaperA4;
worksheet.PageSetup.Orientation = ExcelPageOrientation.Portrait;
worksheet.PageSetup.LeftMargin = 1;
worksheet.PageSetup.RightMargin = 1;
worksheet.PageSetup.TopMargin = 1;
worksheet.PageSetup.BottomMargin = 1;
// add header and footer
//display a logo image in the left part of the header
string imagesPath = System.IO.Path.Combine(Server.MapPath("~"), @"Images");
System.Drawing.Image logoImg = System.Drawing.Image.FromFile(System.IO.Path.Combine(imagesPath, "logo.jpg"));
worksheet.PageSetup.LeftHeaderFormat = "&G";
worksheet.PageSetup.LeftHeaderPicture = logoImg;
// display worksheet name in the right part of the header
worksheet.PageSetup.RightHeaderFormat = "&A";
// add worksheet header and footer
// display the page number in the center part of the footer
worksheet.PageSetup.CenterFooterFormat = "&P";
// display the workbook file name in the left part of the footer
worksheet.PageSetup.LeftFooterFormat = "&F";
// display the current date in the right part of the footer
worksheet.PageSetup.RightFooterFormat = "&D";
#endregion
#region WRITE THE WORKSHEET TOP TITLE
// merge the cells in the range to create the title area
worksheet["A2:G3"].Merge();
// gets the merged range containing the top left cell of the range
ExcelRange titleRange = worksheet["A2"].MergeArea;
// set the text of title area
worksheet["A2"].Text = "Data Types and Data
Formatting Demo";
// set a row height of 18 points for each row in the range
titleRange.RowHeightInPoints = 18;
// set the worksheet top title style
titleRange.Style = titleStyle;
#endregion
#region SET CELLS WITH VARIOUS VALUES AND FORMATTING
worksheet["A1"].ColumnWidthInChars = 16;
worksheet["C1"].ColumnWidthInChars = 16;
worksheet["E1"].ColumnWidthInChars = 16;
worksheet["A5:E5"].Merge();
worksheet["A5:E5"].Style = textMessageStyle;
worksheet["A5:E5"].Value = "String Data Type";
worksheet["A7"].Value = "This is a string
value assigned with 'Value' property";
worksheet["A8"].Text = "This is a string
value assigned with 'Text' property";
worksheet["A10:E10"].Merge();
worksheet["A10:E10"].Style = textMessageStyle;
worksheet["A10:E10"].Value = "Number Data
Type";
double numberValue = 1234567.809;
worksheet["A12"].Value = numberValue;
worksheet["C12"].Value = "Formatting String:";
worksheet["E12"].Value = "Default (General)";
string numberFormatString = "0";
worksheet["A13"].Style.Number.NumberFormatString = numberFormatString;
worksheet["A13"].Value = numberValue;
worksheet["C13"].Value = "Formatting String:";
worksheet["E13"].Value = numberFormatString;
numberFormatString = "0.00";
worksheet["A14"].Value = numberValue;
worksheet["A14"].Style.Number.NumberFormatString = numberFormatString;
worksheet["C14"].Value = "Formatting String:";
worksheet["E14"].Value = numberFormatString;
numberFormatString = "#,##0";
worksheet["A15"].Value = numberValue;
worksheet["A15"].Style.Number.NumberFormatString = numberFormatString;
worksheet["C15"].Value = "Formatting String:";
worksheet["E15"].Value = numberFormatString;
numberFormatString = "#,##0.00";
worksheet["A16"].Value = numberValue;
worksheet["A16"].Style.Number.NumberFormatString = numberFormatString;
worksheet["C16"].Value = "Formatting String:";
worksheet["E16"].Value = numberFormatString;
numberFormatString = "0%";
worksheet["A17"].Value = numberValue;
worksheet["A17"].Style.Number.NumberFormatString = numberFormatString;
worksheet["C17"].Value = "Formatting String:";
worksheet["E17"].Value = numberFormatString;
numberFormatString = "0.00%";
worksheet["A18"].Value = numberValue;
worksheet["A18"].Style.Number.NumberFormatString = numberFormatString;
worksheet["C18"].Value = "Formatting String:";
worksheet["E18"].Value = numberFormatString;
numberFormatString = "0.00E+00";
worksheet["A19"].Value = numberValue;
worksheet["A19"].Style.Number.NumberFormatString = numberFormatString;
worksheet["C19"].Value = "Formatting String:";
worksheet["E19"].Value = numberFormatString;
numberFormatString = "# ?/?";
worksheet["A23"].Value = numberValue;
worksheet["A23"].Style.Number.NumberFormatString = numberFormatString;
worksheet["C23"].Value = "Formatting String:";
worksheet["E23"].Value = numberFormatString;
numberFormatString = "# ??/??";
worksheet["A20"].Value = numberValue;
worksheet["A20"].Style.Number.NumberFormatString = numberFormatString;
worksheet["C20"].Value = "Formatting String:";
worksheet["E20"].Value = numberFormatString;
numberFormatString = @"_( #,##0_);\( #,##0\ )";
worksheet["A21"].Value = numberValue;
worksheet["A21"].Style.Number.NumberFormatString = numberFormatString;
worksheet["C21"].Value = "Formatting String:";
worksheet["E21"].Value = numberFormatString;
numberFormatString = @"_( #,##0_);[Red]\( #,##0\ )";
worksheet["A22"].Value = numberValue;
worksheet["A22"].Style.Number.NumberFormatString = numberFormatString;
worksheet["C22"].Value = "Formatting String:";
worksheet["E22"].Value = numberFormatString;
numberFormatString = @"_( #,##0.00_);\( #,##0.00\ )";
worksheet["A23"].Value = numberValue;
worksheet["A23"].Style.Number.NumberFormatString = numberFormatString;
worksheet["C23"].Value = "Formatting String:";
worksheet["E23"].Value = numberFormatString;
numberFormatString = @"_( #,##0.00_);[Red]\( #,##0.00\ )";
worksheet["A24"].Value = numberValue;
worksheet["A24"].Style.Number.NumberFormatString = numberFormatString;
worksheet["C24"].Value = "Formatting String:";
worksheet["E24"].Value = numberFormatString;
numberFormatString = "_(* #,##0_);_(* \\( #,##0\\ );_(* \"-\"_);_(
@_ )";
worksheet["A25"].Value = numberValue;
worksheet["A25"].Style.Number.NumberFormatString = numberFormatString;
worksheet["C25"].Value = "Formatting String:";
worksheet["E25"].Value = numberFormatString;
numberFormatString = "_(* #,##0.00_);_(* \\( #,##0.00\\ );_(* \"-\"??_);_(
@_ )";
worksheet["A26"].Value = numberValue;
worksheet["A26"].Style.Number.NumberFormatString = numberFormatString;
worksheet["C26"].Value = "Formatting String:";
worksheet["E26"].Value = numberFormatString;
worksheet["A29:E29"].Merge();
worksheet["A29:E29"].Style = textMessageStyle;
worksheet["A29:E29"].Value = "Date and Time";
DateTime dateTimeValue = DateTime.Now;
worksheet["A31"].Value = dateTimeValue;
worksheet["C31"].Value = "Formatting String:";
worksheet["E31"].Value = "Default (mm/dd/yyyy)";
string dateFormatString = "m/d/yyyy";
worksheet["A32"].Value = dateTimeValue;
worksheet["A32"].Style.Number.NumberFormatString = dateFormatString;
worksheet["C32"].Value = "Formatting String:";
worksheet["E32"].Value = dateFormatString;
dateFormatString = @"d\-mmm\-yy";
worksheet["A33"].Value = dateTimeValue;
worksheet["A33"].Style.Number.NumberFormatString = dateFormatString;
worksheet["C33"].Value = "Formatting String:";
worksheet["E33"].Value = dateFormatString;
dateFormatString = @"d\-mmm";
worksheet["A34"].Value = dateTimeValue;
worksheet["A34"].Style.Number.NumberFormatString = dateFormatString;
worksheet["C34"].Value = "Formatting String:";
worksheet["E34"].Value = dateFormatString;
dateFormatString = @"d\-mmm";
worksheet["A35"].Value = dateTimeValue;
worksheet["A35"].Style.Number.NumberFormatString = dateFormatString;
worksheet["C35"].Value = "Formatting String:";
worksheet["E35"].Value = dateFormatString;
dateFormatString = @"mmm\-yy";
worksheet["A36"].Value = dateTimeValue;
worksheet["A36"].Style.Number.NumberFormatString = dateFormatString;
worksheet["C36"].Value = "Formatting String:";
worksheet["E36"].Value = dateFormatString;
dateFormatString = @"h:mm AM/PM";
worksheet["A37"].Value = dateTimeValue;
worksheet["A37"].Style.Number.NumberFormatString = dateFormatString;
worksheet["C37"].Value = "Formatting String:";
worksheet["E37"].Value = dateFormatString;
dateFormatString = @"h:mm:ss AM/PM";
worksheet["A38"].Value = dateTimeValue;
worksheet["A38"].Style.Number.NumberFormatString = dateFormatString;
worksheet["C38"].Value = "Formatting String:";
worksheet["E38"].Value = dateFormatString;
dateFormatString = @"h:mm";
worksheet["A39"].Value = dateTimeValue;
worksheet["A39"].Style.Number.NumberFormatString = dateFormatString;
worksheet["C39"].Value = "Formatting String:";
worksheet["E39"].Value = dateFormatString;
dateFormatString = @"h:mm:ss";
worksheet["A40"].Value = dateTimeValue;
worksheet["A40"].Style.Number.NumberFormatString = dateFormatString;
worksheet["C40"].Value = "Formatting String:";
worksheet["E40"].Value = dateFormatString;
dateFormatString = @"m/d/yy h:mm";
worksheet["A41"].Value = dateTimeValue;
worksheet["A41"].Style.Number.NumberFormatString = dateFormatString;
worksheet["C41"].Value = "Formatting String:";
worksheet["E41"].Value = dateFormatString;
#endregion
// Save the Excel document in the current HTTP response stream
string outFileName = workbookFormat == ExcelWorkbookFormat.Xls_2003 ? "DataTypes.xls" : "DataTypes.xlsx";
System.Web.HttpResponse httpResponse = System.Web.HttpContext.Current.Response;
// Prepare the HTTP response stream for saving the Excel document
// Clear any data that might have been previously buffered in the
output stream
httpResponse.Clear();
// Set output stream content type for Excel 97-2003 (.xls) or Excel
2007 (.xlsx)
if (workbookFormat == ExcelWorkbookFormat.Xls_2003)
httpResponse.ContentType = "Application/x-msexcel";
else
httpResponse.ContentType = "Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
// Add the HTTP header to announce the Excel document either as an
attachment or inline
httpResponse.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", outFileName));
// Save the workbook to the current HTTP response output stream
// and close the workbook after save to release all the allocated
resources
try
{
workbook.Save(httpResponse.OutputStream);
}
catch (Exception ex)
{
// report any error that might occur during save
Session["ErrorMessage"] = ex.Message;
Response.Redirect("ErrorPage.aspx");
}
finally
{
// close the workbook and release the allocated resources
workbook.Close();
#region Dispose the Image object
if (logoImg != null)
logoImg.Dispose();
#endregion
}
// End the response and finish the execution of this page
httpResponse.End();
}
Protected Sub lnkBtnCreateWorkbook_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles lnkBtnCreateWorkbook.Click
' get the Excel workbook format
Dim workbookFormat As ExcelWorkbookFormat
If radioXlsFormat.Checked Then
workbookFormat = ExcelWorkbookFormat.Xls_2003
Else
workbookFormat = ExcelWorkbookFormat.Xlsx_2007
End If
' create the workbook in the desired format with a single worksheet
Dim workbook As ExcelWorkbook = New ExcelWorkbook(workbookFormat)
' set the license key before saving the workbook
workbook.LicenseKey = "RW51ZXZ0ZXVldGt1ZXZ0a3R3a3x8fHw="
' set workbook description properties
workbook.DocumentProperties.Subject = "Data types and data formatting
demo"
workbook.DocumentProperties.Comments =
"Add formatted data to an Excel worksheet using Winnovative Excel
library for .NET"
' CREATE CUSTOM WORKBOOK STYLES
' Add a style used for the cells in the worksheet title area
Dim titleStyle As ExcelCellStyle = workbook.Styles.AddStyle("WorksheetTitleStyle")
' center the text in the title area
titleStyle.Alignment.HorizontalAlignment = ExcelCellHorizontalAlignmentType.Center
titleStyle.Alignment.VerticalAlignment = ExcelCellVerticalAlignmentType.Center
' set the title area borders
titleStyle.Borders.Item(ExcelCellBorderIndex.Bottom).Color = Color.Green
titleStyle.Borders.Item(ExcelCellBorderIndex.Bottom).LineStyle = ExcelCellLineStyle.Medium
titleStyle.Borders.Item(ExcelCellBorderIndex.Top).Color = Color.Green
titleStyle.Borders.Item(ExcelCellBorderIndex.Top).LineStyle = ExcelCellLineStyle.Medium
titleStyle.Borders.Item(ExcelCellBorderIndex.Left).Color = Color.Green
titleStyle.Borders.Item(ExcelCellBorderIndex.Left).LineStyle = ExcelCellLineStyle.Medium
titleStyle.Borders.Item(ExcelCellBorderIndex.Right).Color = Color.Green
titleStyle.Borders.Item(ExcelCellBorderIndex.Right).LineStyle = ExcelCellLineStyle.Medium
If workbookFormat = ExcelWorkbookFormat.Xls_2003 Then
' set the solid fill for the title area range with a custom color
titleStyle.Fill.FillType = ExcelCellFillType.SolidFill
titleStyle.Fill.SolidFillOptions.BackColor = Color.FromArgb(255, 255, 204)
Else
' set the gradient fill for the title area range with a custom color
titleStyle.Fill.FillType = ExcelCellFillType.GradientFill
titleStyle.Fill.GradientFillOptions.Color1 = Color.FromArgb(255, 255, 204)
titleStyle.Fill.GradientFillOptions.Color2 = Color.White
End If
' set the title area font
titleStyle.Font.Size = 14
titleStyle.Font.Bold = True
titleStyle.Font.UnderlineType = ExcelCellUnderlineType.Single
'Add a style used for text messages
Dim textMessageStyle As ExcelCellStyle = workbook.Styles.AddStyle("TextMessageStyle")
textMessageStyle.Font.Size = 10
textMessageStyle.Font.Bold = True
textMessageStyle.Alignment.VerticalAlignment = ExcelCellVerticalAlignmentType.Center
textMessageStyle.Alignment.HorizontalAlignment = ExcelCellHorizontalAlignmentType.Left
textMessageStyle.Fill.FillType = ExcelCellFillType.SolidFill
textMessageStyle.Fill.SolidFillOptions.BackColor = Color.FromArgb(204, 255, 204)
textMessageStyle.Borders.Item(ExcelCellBorderIndex.Bottom).LineStyle = ExcelCellLineStyle.Thin
textMessageStyle.Borders.Item(ExcelCellBorderIndex.Top).LineStyle = ExcelCellLineStyle.Thin
textMessageStyle.Borders.Item(ExcelCellBorderIndex.Left).LineStyle = ExcelCellLineStyle.Thin
textMessageStyle.Borders.Item(ExcelCellBorderIndex.Right).LineStyle = ExcelCellLineStyle.Thin
' Add a style used for data validation ranges
Dim dataValidationStyle As ExcelCellStyle = workbook.Styles.AddStyle("DataValidationStyle")
dataValidationStyle.Font.Size = 10
dataValidationStyle.Font.Bold = True
dataValidationStyle.Alignment.VerticalAlignment = ExcelCellVerticalAlignmentType.Center
dataValidationStyle.Fill.FillType = ExcelCellFillType.SolidFill
dataValidationStyle.Fill.SolidFillOptions.BackColor = Color.FromArgb(153, 204, 0)
dataValidationStyle.Borders.Item(ExcelCellBorderIndex.Bottom).LineStyle = ExcelCellLineStyle.Thin
dataValidationStyle.Borders.Item(ExcelCellBorderIndex.Top).LineStyle = ExcelCellLineStyle.Thin
dataValidationStyle.Borders.Item(ExcelCellBorderIndex.Left).LineStyle = ExcelCellLineStyle.Thin
dataValidationStyle.Borders.Item(ExcelCellBorderIndex.Right).LineStyle = ExcelCellLineStyle.Thin
' get the first worksheet in the workbook
Dim worksheet As ExcelWorksheet = workbook.Worksheets.Item(0)
' set the default worksheet name
worksheet.Name = "Data Types Demo"
' WORKSHEET PAGE SETUP
' set worksheet paper size and orientation, margins, header and footer
worksheet.PageSetup.PaperSize = ExcelPagePaperSize.PaperA4
worksheet.PageSetup.Orientation = ExcelPageOrientation.Portrait
worksheet.PageSetup.LeftMargin = 1
worksheet.PageSetup.RightMargin = 1
worksheet.PageSetup.TopMargin = 1
worksheet.PageSetup.BottomMargin = 1
' add header and footer
'display a logo image in the left part of the header
Dim imagesPath As String = System.IO.Path.Combine(Server.MapPath("~"), "Images")
Dim logoImg As System.Drawing.Image = System.Drawing.Image.FromFile(System.IO.Path.Combine(imagesPath, "logo.jpg"))
worksheet.PageSetup.LeftHeaderFormat = "&G"
worksheet.PageSetup.LeftHeaderPicture = logoImg
' display worksheet name in the right part of the header
worksheet.PageSetup.RightHeaderFormat = "&A"
' add worksheet header and footer
' display the page number in the center part of the footer
worksheet.PageSetup.CenterFooterFormat = "&P"
' display the workbook file name in the left part of the footer
worksheet.PageSetup.LeftFooterFormat = "&F"
' display the current date in the right part of the footer
worksheet.PageSetup.RightFooterFormat = "&D"
' WRITE THE WORKSHEET TOP TITLE
' merge the cells in the range to create the title area
worksheet.Item("A2:G3").Merge()
' gets the merged range containing the top left cell of the range
Dim titleRange As ExcelRange = worksheet.Item("A2").MergeArea
' set the text of title area
worksheet.Item("A2").Text = "Data Types and
Data Formatting Demo"
' set a row height of 18 points for each row in the range
titleRange.RowHeightInPoints = 18
' set the worksheet top title style
titleRange.Style = titleStyle
' SET CELLS WITH VARIOUS VALUES AND FORMATTING
worksheet.Item("A1").ColumnWidthInChars = 16
worksheet.Item("C1").ColumnWidthInChars = 16
worksheet.Item("E1").ColumnWidthInChars = 16
worksheet.Item("A5:E5").Merge()
worksheet.Item("A5:E5").Style = textMessageStyle
worksheet.Item("A5:E5").Value = "String Data
Type"
worksheet.Item("A7").Value = "This is a string
value assigned with 'Value' property"
worksheet.Item("A8").Text = "This is a string
value assigned with 'Text' property"
worksheet.Item("A10:E10").Merge()
worksheet.Item("A10:E10").Style = textMessageStyle
worksheet.Item("A10:E10").Value = "Number
Data Type"
Dim numberValue As Double = 1234567.809
worksheet.Item("A12").Value = numberValue
worksheet.Item("C12").Value = "Formatting
String:"
worksheet.Item("E12").Value = "Default (General)"
Dim numberFormatString As String = "0"
worksheet.Item("A13").Value = numberValue
worksheet.Item("A13").Style.Number.NumberFormatString = numberFormatString
worksheet.Item("C13").Value = "Formatting
String:"
worksheet.Item("E13").Value = numberFormatString
numberFormatString = "0.00"
worksheet.Item("A14").Value = numberValue
worksheet.Item("A14").Style.Number.NumberFormatString = numberFormatString
worksheet.Item("C14").Value = "Formatting
String:"
worksheet.Item("E14").Value = numberFormatString
numberFormatString = "#,##0"
worksheet.Item("A15").Value = numberValue
worksheet.Item("A15").Style.Number.NumberFormatString = numberFormatString
worksheet.Item("C15").Value = "Formatting
String:"
worksheet.Item("E15").Value = numberFormatString
numberFormatString = "#,##0.00"
worksheet.Item("A16").Value = numberValue
worksheet.Item("A16").Style.Number.NumberFormatString = numberFormatString
worksheet.Item("C16").Value = "Formatting
String:"
worksheet.Item("E16").Value = numberFormatString
numberFormatString = "0%"
worksheet.Item("A17").Value = numberValue
worksheet.Item("A17").Style.Number.NumberFormatString = numberFormatString
worksheet.Item("C17").Value = "Formatting
String:"
worksheet.Item("E17").Value = numberFormatString
numberFormatString = "0.00%"
worksheet.Item("A18").Value = numberValue
worksheet.Item("A18").Style.Number.NumberFormatString = numberFormatString
worksheet.Item("C18").Value = "Formatting
String:"
worksheet.Item("E18").Value = numberFormatString
numberFormatString = "0.00E+00"
worksheet.Item("A19").Value = numberValue
worksheet.Item("A19").Style.Number.NumberFormatString = numberFormatString
worksheet.Item("C19").Value = "Formatting
String:"
worksheet.Item("E19").Value = numberFormatString
numberFormatString = "# ?/?"
worksheet.Item("A20").Value = numberValue
worksheet.Item("A20").Style.Number.NumberFormatString = numberFormatString
worksheet.Item("C20").Value = "Formatting
String:"
worksheet.Item("E20").Value = numberFormatString
numberFormatString = "# ??/??"
worksheet.Item("A21").Value = numberValue
worksheet.Item("A21").Style.Number.NumberFormatString = numberFormatString
worksheet.Item("C21").Value = "Formatting
String:"
worksheet.Item("E21").Value = numberFormatString
numberFormatString = "_( #,##0_);\( #,##0\ )"
worksheet.Item("A25").Value = numberValue
worksheet.Item("A25").Style.Number.NumberFormatString = numberFormatString
worksheet.Item("C25").Value = "Formatting
String:"
worksheet.Item("E25").Value = numberFormatString
numberFormatString = "_( #,##0_);[Red]\( #,##0\ )"
worksheet.Item("A22").Value = numberValue
worksheet.Item("A22").Style.Number.NumberFormatString = numberFormatString
worksheet.Item("C22").Value = "Formatting
String:"
worksheet.Item("E22").Value = numberFormatString
numberFormatString = "_( #,##0.00_);\( #,##0.00\ )"
worksheet.Item("A23").Value = numberValue
worksheet.Item("A23").Style.Number.NumberFormatString = numberFormatString
worksheet.Item("C23").Value = "Formatting
String:"
worksheet.Item("E23").Value = numberFormatString
numberFormatString = "_( #,##0.00_);[Red]\( #,##0.00\ )"
worksheet.Item("A24").Value = numberValue
worksheet.Item("A24").Style.Number.NumberFormatString = numberFormatString
worksheet.Item("C24").Value = "Formatting
String:"
worksheet.Item("E24").Value = numberFormatString
numberFormatString = "_(* #,##0_);_(* \( #,##0\ );_(* ""-""_);_( @_ )"
worksheet.Item("A25").Value = numberValue
worksheet.Item("A25").Style.Number.NumberFormatString = numberFormatString
worksheet.Item("C25").Value = "Formatting
String:"
worksheet.Item("E25").Value = numberFormatString
numberFormatString = "_(* #,##0.00_);_(* \( #,##0.00\ );_(* ""-""??_);_( @_ )"
worksheet.Item("A26").Value = numberValue
worksheet.Item("A26").Style.Number.NumberFormatString = numberFormatString
worksheet.Item("C26").Value = "Formatting
String:"
worksheet.Item("E26").Value = numberFormatString
worksheet.Item("A29:E29").Merge()
worksheet.Item("A29:E29").Style = textMessageStyle
worksheet.Item("A29:E29").Value = "Date and
Time"
Dim dateTimeValue As DateTime = DateTime.Now
worksheet.Item("A31").Value = dateTimeValue
worksheet.Item("C31").Value = "Formatting
String:"
worksheet.Item("E31").Value = "Default (mm/dd/yyyy)"
Dim dateFormatString As String = "m/d/yyyy"
worksheet.Item("A32").Value = dateTimeValue
worksheet.Item("A32").Style.Number.NumberFormatString = dateFormatString
worksheet.Item("C32").Value = "Formatting
String:"
worksheet.Item("E32").Value = dateFormatString
dateFormatString = "d\-mmm\-yy"
worksheet.Item("A33").Value = dateTimeValue
worksheet.Item("A33").Style.Number.NumberFormatString = dateFormatString
worksheet.Item("C33").Value = "Formatting
String:"
worksheet.Item("E33").Value = dateFormatString
dateFormatString = "d\-mmm"
worksheet.Item("A34").Value = dateTimeValue
worksheet.Item("A34").Style.Number.NumberFormatString = dateFormatString
worksheet.Item("C34").Value = "Formatting
String:"
worksheet.Item("E34").Value = dateFormatString
dateFormatString = "d\-mmm"
worksheet.Item("A35").Value = dateTimeValue
worksheet.Item("A35").Style.Number.NumberFormatString = dateFormatString
worksheet.Item("C35").Value = "Formatting
String:"
worksheet.Item("E35").Value = dateFormatString
dateFormatString = "mmm\-yy"
worksheet.Item("A36").Value = dateTimeValue
worksheet.Item("A36").Style.Number.NumberFormatString = dateFormatString
worksheet.Item("C36").Value = "Formatting
String:"
worksheet.Item("E36").Value = dateFormatString
dateFormatString = "h:mm AM/PM"
worksheet.Item("A37").Value = dateTimeValue
worksheet.Item("A37").Style.Number.NumberFormatString = dateFormatString
worksheet.Item("C37").Value = "Formatting
String:"
worksheet.Item("E37").Value = dateFormatString
dateFormatString = "h:mm:ss AM/PM"
worksheet.Item("A38").Value = dateTimeValue
worksheet.Item("A38").Style.Number.NumberFormatString = dateFormatString
worksheet.Item("C38").Value = "Formatting
String:"
worksheet.Item("E38").Value = dateFormatString
dateFormatString = "h:mm"
worksheet.Item("A39").Value = dateTimeValue
worksheet.Item("A39").Style.Number.NumberFormatString = dateFormatString
worksheet.Item("C39").Value = "Formatting
String:"
worksheet.Item("E39").Value = dateFormatString
dateFormatString = "h:mm:ss"
worksheet.Item("A40").Value = dateTimeValue
worksheet.Item("A40").Style.Number.NumberFormatString = dateFormatString
worksheet.Item("C40").Value = "Formatting
String:"
worksheet.Item("E40").Value = dateFormatString
dateFormatString = "m/d/yy h:mm"
worksheet.Item("A41").Value = dateTimeValue
worksheet.Item("A41").Style.Number.NumberFormatString = dateFormatString
worksheet.Item("C41").Value = "Formatting
String:"
worksheet.Item("E41").Value = dateFormatString
' SAVE THE WORKBOOK
' Save the Excel document in the current HTTP response stream
Dim outFileName As String
If workbookFormat = ExcelWorkbookFormat.Xls_2003 Then
outFileName = "DataTypes.xls"
Else
outFileName = "DataTypes.xlsx"
End If
Dim httpResponse As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
' Prepare the HTTP response stream for saving the Excel document
' Clear any data that might have been previously buffered in the output
stream
httpResponse.Clear()
' Set output stream content type for Excel 97-2003 (.xls) or Excel
2007 (.xlsx)
If workbookFormat = ExcelWorkbookFormat.Xls_2003 Then
httpResponse.ContentType = "Application/x-msexcel"
Else
httpResponse.ContentType = "Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
End If
' Add the HTTP header to announce the Excel document either as an
attachment or inline
httpResponse.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", outFileName))
' Save the workbook to the current HTTP response output stream
' and close the workbook after save to release all the allocated resources
Try
workbook.Save(httpResponse.OutputStream)
Catch ex As Exception
' report any error that might occur during save
Session.Item("ErrorMessage") = ex.Message
Response.Redirect("ErrorPage.aspx")
Finally
' close the workbook and release the allocated resources
workbook.Close()
' Dispose the Image object
If Not logoImg Is Nothing Then
logoImg.Dispose()
End If
End Try
' End the response and finish the execution of this page
httpResponse.End()
End Sub
|