Generates an Excel file with a header, formatted as shown below.
Of course, some of the more complicated things can also be implemented by merging cells by using the method public void merge (int firstrow, int firstcolumn, int totalrows, int totalcolumns).
1. First, you need to add a reference to "Aspose.Cells.dll".
2. The implementation code is as follows:
Create a new workbook
Workbook workbook = new Workbook (); Work book
Worksheet sheet = workbook. Worksheets[0]; Work table
Cells Cells = sheet. cells;//cell
Style style = workbook. Styles[workbook. Styles.add ()];//new style
#region Table Header
Title
Style. HorizontalAlignment = textalignmenttype.center;//text centered
Style. Font.Name = "Song body";//Text font
Style. Font.Size = 18;//Text Size
Style. Font.isbold = true;//Bold
cells. Merge (0, 0, 1,); //merged cells
cells[0, 0]. Putvalue ("Standardized Work advice summary form"); //Fill in content
cells[0, 0]. SetStyle (Style); //To Cell Association style
cells. Setrowheight (0); //Set row height
//Publish Time
style. HorizontalAlignment = Textalignmenttype.left;
style. Font.Size = 11;
style. Font.isbold = false;
cells. Merge (1, 0, 1, 7);
cells[1, 0]. Putvalue (String.Format ("Publish from: {0} to {1}", DateTime.Now.AddDays (-1). ToString ("YYYY year mm month DD Day"), DateTime.Now.ToString ("yyyy mm month DD day"));
cells[1, 0]. SetStyle (style);
cells. Setrowheight (1);
//Statistics TIME
style. HorizontalAlignment = Textalignmenttype.right;
style. Font.Size = 11;
style. Font.isbold = false;
cells. Merge (1, 7, 1, 5);
cells[1, 7]. Putvalue (String.Format ("statistic time: {0}", DateTime.Now.ToString ("YYYY year mm month DD Day"));
cells[1, 7]. SetStyle (style);
cells. Setrowheight (1, 20);
#endregion
#region Table
#region Table header row
Serial number
Style. HorizontalAlignment = Textalignmenttype.center;
Cells[2, 0]. Putvalue ("serial number");
Cells[2, 0]. SetStyle (style);
Cells. Setrowheight (2, 20);
Cells. Setcolumnwidthpixel (0, 38);
Recommended time
Cells[2, 1]. Putvalue ("Suggested Time");
Cells[2, 1]. SetStyle (style);
Cells. Setcolumnwidthpixel (1, 77);
Suggested department
Cells[2, 2]. Putvalue ("proposed department");
Cells[2, 2]. SetStyle (style);
Cells. Setcolumnwidthpixel (2, 107);
Advise people
Cells[2, 3]. Putvalue ("advising person");
Cells[2, 3]. SetStyle (style);
Cells. Setcolumnwidthpixel (3, 69);
Category
Cells[2, 4]. Putvalue ("category");
Cells[2, 4]. SetStyle (style);
Cells. Setcolumnwidthpixel (4, 71);
Type of Business
Cells[2, 5]. Putvalue ("Type of Business");
Cells[2, 5]. SetStyle (style);
Cells. Setcolumnwidthpixel (5, 71);
Standard name
Cells[2, 6]. Putvalue ("standard name");
Cells[2, 6]. SetStyle (style);
Cells. Setcolumnwidthpixel (6, 114);
Standard Chapter, article number
Cells[2, 7]. Putvalue ("standard chapter, article number");
Cells[2, 7]. SetStyle (style);
Cells. Setcolumnwidthpixel (7, 104);
Comments and Suggestions
Cells[2, 8]. Putvalue ("Opinion proposal");
Cells[2, 8]. SetStyle (style);
Cells. Setcolumnwidthpixel (8, 255);
Processing Department
Cells[2, 9]. Putvalue ("processing department");
Cells[2, 9]. SetStyle (style);
Cells. Setcolumnwidthpixel (9, 72);
Process Progress
Cells[2, 10]. Putvalue ("Process progress");
Cells[2, 10]. SetStyle (style);
Cells. Setcolumnwidthpixel (10, 72);
Note
Cells[2, 11]. Putvalue ("Remarks");
Cells[2, 11]. SetStyle (style);
Cells. Setcolumnwidthpixel (11, 255);
#endregion
#endregion
System.IO.MemoryStream ms = Workbook. Savetostream ()//Generate data stream
byte[] bt = Ms. ToArray ();
Workbook. Save (@ "E:\test.xls");//saved to hard disk
}