JavascriptExcel operation knowledge point _ javascript skills
Source: Internet
Author: User
Use ActiveXObject in JavaScript to fill in and set the Excel format
1. Create Var XLObj = new ActiveXObject ("Excel. Application ");
Var xlBook = XLObj. Workbooks. Add; // Add a workbook
Var ExcelSheet = xlBook. Worksheets (1); // create a worksheet
2. Save the table ExcelSheet. SaveAs ("C :\\ TEST. XLS ");
3. Make Excel visible through Application object ExcelSheet. Application. Visible = true;
4. Print XlBook. PrintOut;
Or:
ExcelSheet. PrintOut;
5. Disable XlBook. Close (savechanges = false );
Or:
ExcelSheet. Close (savechanges = false );
6. End the process ExcelSheet. Application. Quit ();
Or:
XLObj. Quit ();
XLObj = null;
7. Page settings ExcelSheet. ActiveSheet. PageSetup. LeftMargin = 2/0. 035;
// The margin is 2 cm left.
ExcelSheet. ActiveSheet. PageSetup. RightMargin = 3/0. 035;
// The right margin of the page is 3 cm
ExcelSheet. ActiveSheet. PageSetup. TopMargin = 4/0. 035;
// 4 cm Margin
ExcelSheet. ActiveSheet. PageSetup. BottomMargin = 5/0. 035;
// The page margin is 5 cm
ExcelSheet. ActiveSheet. PageSetup. HeaderMargin = 1/0. 035;
// The page header is 1 cm
ExcelSheet. ActiveSheet. PageSetup. FooterMargin = 2/0. 035;
// Footer 2 cm
ExcelSheet. ActiveSheet. PageSetup. CenterHeader = "content in the middle of the header ";
ExcelSheet. ActiveSheet. PageSetup. LeftHeader = "header left content ";
ExcelSheet. ActiveSheet. PageSetup. RightHeader = "content on the right of the header ";
ExcelSheet. ActiveSheet. PageSetup. CenterFooter = "content in the middle of the footer ";
ExcelSheet. ActiveSheet. PageSetup. LeftFooter = "Left footer content ";
ExcelSheet. ActiveSheet. PageSetup. RightFooter = "content on the right of the footer ";
8. Operate on cells. The "*" section has corresponding attributes for rows, columns, and regions. ExcelSheet. ActiveSheet. Cells (row, col). Value = "content ";
// Set the cell content
ExcelSheet. ActiveSheet. Cells (row, col). Borders. Weight = 1;
// Set the cell border *()
ExcelSheet. ActiveSheet. Cells (row, col). Interior. ColorIndex = 1;
// Set the cell background color * (1-black, 2-white, 3-red, 4-green, 5-blue, 6-yellow, 7-pink, 8-day blue, 9-soil color of sauce .. can do more)
ExcelSheet. ActiveSheet. Cells (row, col). Interior. Pattern = 1;
// Set the cell background style * (1-None, 2-fine grid, 3-coarse grid, 4-spots, 5-horizontal lines, 6-vertical lines .. you can try more)
ExcelSheet. ActiveSheet. Cells (row, col). Font. ColorIndex = 1;
// Set the font color * (same as above)
ExcelSheet. ActiveSheet. Cells (row, col). Font. Size = 10;
// Set it to 10 characters *
ExcelSheet. ActiveSheet. Cells (row, col). Font. Name = "";
// Set it to *
ExcelSheet. ActiveSheet. Cells (row, col). Font. Italic = true;
// Set it to italic *
ExcelSheet. ActiveSheet. Cells (row, col). Font. Bold = true;
// Set it to bold *
ExcelSheet. ActiveSheet. Cells (row, col). ClearContents;
// Clear content *
ExcelSheet. ActiveSheet. Cells (row, col). WrapText = true;
// Set to automatic line feed *
ExcelSheet. ActiveSheet. Cells (row, col). HorizontalAlignment = 3;
// Horizontal alignment enumeration * (1-regular, 2-to left, 3-center, 4-to right, 5-fill 6-align at both ends, 7-center across columns, 8-distributed alignment)
ExcelSheet. ActiveSheet. Cells (row, col). verticalignment = 2;
// Vertical alignment enumeration * (1-up, 2-center, 3-down, 4-aligned, 5-aligned)
Rows and columns have the following operations:
ExcelSheet. ActiveSheet. Rows (row ).
ExcelSheet. ActiveSheet. Columns (col ).
ExcelSheet. ActiveSheet. Rows (startrow + ":" + endrow ).
// For example, Rows ("") means 1 to 5 Rows.
ExcelSheet. ActiveSheet. Columns (startcol + ":" + endcol ).
// For example, Columns ("") is 1 to 5 Columns.
The region has the following operations:
XLObj. Range (startcell + ":" + endcell). Select;
// For example, Range ("A2: H8") indicates the entire area of column A's 2nd grids to column H's 8th grids.
XLObj. Selection.
Merge Cells
XLObj. Range (startcell + ":" + endcell). MergeCells = true;
// For example, Range ("A2: H8") merges the entire area of column A's 2nd grids to column H's 8th grids into A cell.
XLObj. Range ("A2", XLObj. Cells (8, 8). MergeCells = true;
9. Set the Row Height and column width.
ExcelSheet. ActiveSheet. Columns (startcol + ":" + endcol). ColumnWidth = 22;
// Set the width of the columns from firstcol to stopcol to 22.
ExcelSheet. ActiveSheet. Rows (startrow + ":" + endrow). RowHeight = 22;
// Set the row width from firstrow to stoprow to 22
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.