JavaScript Excel operation knowledge Point _javascript skill
Source: Internet
Author: User
1 Creating
var xlobj = new ActiveXObject ("Excel.Application");
var xlbook = XLObj.Workbooks.Add; New Workbook
var excelsheet = xlbook.worksheets (1); Create a worksheet
2. Save the form
Excelsheet.saveas ("C:\\test.") XLS ");
3. Make Excel visible through application objects
ExcelSheet.Application.Visible = true;
4. Print
Xlbook.printout;
Or:
Excelsheet.printout;
5. Close
Xlbook.close (Savechanges=false);
Or:
Excelsheet.close (Savechanges=false);
6. Closing the process
ExcelSheet.Application.Quit ();
Or:
Xlobj.quit ();
Xlobj=null;
7. Page Setup
Excelsheet.activesheet.pagesetup.leftmargin= 2/0.035;
Margins left 2 cm
ExcelSheet.ActiveSheet.PageSetup.RightMargin = 3/0.035;
Page margin right 3 cm
ExcelSheet.ActiveSheet.PageSetup.TopMargin = 4/0.035;
Page margin 4 cm
ExcelSheet.ActiveSheet.PageSetup.BottomMargin = 5/0.035;
5 cm below margin
ExcelSheet.ActiveSheet.PageSetup.HeaderMargin = 1/0.035;
Page margin Header 1 cm
ExcelSheet.ActiveSheet.PageSetup.FooterMargin = 2/0.035;
Page margin Footer 2 cm
ExcelSheet.ActiveSheet.PageSetup.CenterHeader = "Central header content";
ExcelSheet.ActiveSheet.PageSetup.LeftHeader = "Left part of header";
ExcelSheet.ActiveSheet.PageSetup.RightHeader = "Right section of header content";
ExcelSheet.ActiveSheet.PageSetup.CenterFooter = "middle footer content";
ExcelSheet.ActiveSheet.PageSetup.LeftFooter = "Footer left part";
ExcelSheet.ActiveSheet.PageSetup.RightFooter = "footer Right part";
8. For cell operations, with the * section for rows, columns, areas have corresponding properties
ExcelSheet.ActiveSheet.Cells (Row,col). Value = "Content";
Set cell contents
ExcelSheet.ActiveSheet.Cells (Row,col). Borders.Weight = 1;
Set cell borders * ()
ExcelSheet.ActiveSheet.Cells (Row,col). Interior.ColorIndex = 1;
Set Cell background Color * (1-black, 2-white, 3-red, 4-green, 5-blue, 6-yellow, 7-pink, 8-sky-blue, 9-paste soil color). Can do more to try)
ExcelSheet.ActiveSheet.Cells (Row,col). Interior.Pattern = 1;
Set cell background style * (1-None, 2-Fine mesh, 3-thick mesh, 4-dot, 5-horizontal, 6-vertical). Can do more to try)
ExcelSheet.ActiveSheet.Cells (Row,col). Font.ColorIndex = 1;
Set Font color * (same as above)
ExcelSheet.ActiveSheet.Cells (Row,col). Font.Size = 10;
Set to number 10th *
ExcelSheet.ActiveSheet.Cells (Row,col). Font.Name = "Blackbody";
Set to Bold *
ExcelSheet.ActiveSheet.Cells (Row,col). Font.Italic = true;
Set to Italic *
ExcelSheet.ActiveSheet.Cells (Row,col). Font.Bold = true;
Set to Bold *
ExcelSheet.ActiveSheet.Cells (Row,col). clearcontents;
Clear content *
ExcelSheet.ActiveSheet.Cells (Row,col). Wraptext=true;
Set to wrap automatically *
ExcelSheet.ActiveSheet.Cells (Row,col). HorizontalAlignment = 3;
Horizontal Alignment Enumeration * (2-left, 3-centered, 4-right, 5-fill 6-Justified, 7-cross-column center, 8-distributed alignment)
ExcelSheet.ActiveSheet.Cells (Row,col). VerticalAlignment = 2;
Vertical Alignment Enumeration * (1-up, 2-centered, 3-down, 4-justified, 5-distributed)
Row, the column has the appropriate action:
ExcelSheet.ActiveSheet.Rows (Row).
ExcelSheet.ActiveSheet.Columns (COL).
ExcelSheet.ActiveSheet.Rows (startrow+ ":" +endrow).
If rows ("1:5") is 1 to 5 lines
ExcelSheet.ActiveSheet.Columns (startcol+ ":" +endcol).
such as columns ("1:5") that is 1 to 5 columns
The area has a corresponding action:
Xlobj.range (startcell+ ":" +endcell). Select;
such as Range ("A2:h8") is the entire area of column A, 2nd to column H, Grid 8th
Xlobj.selection.
Merging cells
Xlobj.range (startcell+ ":" +endcell). MergeCells = true;
such as Range ("A2:h8") merges the entire range of columns 2nd through column A to column 8th in a cell
Xlobj.range ("A2", Xlobj.cells (8,8)). MergeCells = true;
9. Set row height and column width
ExcelSheet.ActiveSheet.Columns (startcol+ ":" +endcol). ColumnWidth = 22;
Sets the width from Firstcol to stopcol columns to 22
ExcelSheet.ActiveSheet.Rows (startrow+ ":" +endrow). RowHeight = 22;
Sets the width of the line 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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service