Home  >  Article  >  Web Front-end  >  javascript Excel operation knowledge points_javascript skills

javascript Excel operation knowledge points_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:53:43975browse
1Create
var XLObj = new ActiveXObject("Excel.Application" );
var xlBook = XLObj.Workbooks.Add; //Add a new workbook
var ExcelSheet = xlBook. Worksheets(1); //Create worksheet
2. Save the table
ExcelSheet.SaveAs("C:\TEST.XLS" );
3. Use Excel Visible through Application object
ExcelSheet.Application.Visible = true;
4. Print
xlBook.PrintOut;
or:
ExcelSheet.PrintOut;
5. Close
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 page margin is 2 cm left
ExcelSheet.ActiveSheet.PageSetup.RightMargin = 3/0.035;
//The page margin is 3 cm right
ExcelSheet.ActiveSheet.PageSetup.TopMargin = 4/0.035;
//Top margin 4 cm
ExcelSheet.ActiveSheet.PageSetup.BottomMargin = 5/0.035;
//Bottom margin 5cm
ExcelSheet.ActiveSheet.PageSetup.HeaderMargin = 1/0.035;
//Margin Header 1cm
ExcelSheet.ActiveSheet.PageSetup.FooterMargin = 2/0.035;
//Page Margin footer 2 cm
ExcelSheet.ActiveSheet.PageSetup.CenterHeader = "Header content in the middle";
ExcelSheet.ActiveSheet.PageSetup.LeftHeader = "Header left content";
ExcelSheet.ActiveSheet. PageSetup.RightHeader = "The content of the right part of the header";
ExcelSheet.ActiveSheet.PageSetup.CenterFooter = "The content of the middle part of the footer";
ExcelSheet.ActiveSheet.PageSetup.LeftFooter = "The content of the left part of the footer";
ExcelSheet.ActiveSheet.PageSetup.RightFooter = "Footer right content";
8. For cell operations, the part with * has corresponding properties for rows, columns, and regions
ExcelSheet.ActiveSheet.Cells(row,col).Value = "Content";
//Set cell content
ExcelSheet.ActiveSheet.Cells(row,col).Borders.Weight = 1;
/ /Set cell border*()
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-dark earth color. You can try more)
ExcelSheet.ActiveSheet.Cells(row,col) .Interior.Pattern = 1;
//Set 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 to size 10*
ExcelSheet.ActiveSheet.Cells(row,col).Font.Name = "Black";
//Set to Black *
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 automatic line wrapping*
ExcelSheet.ActiveSheet.Cells(row,col).HorizontalAlignment = 3;
//Horizontal alignment enumeration* (1-normal, 2-left , 3-center, 4-right, 5-fill 6-align both ends, 7-center across columns, 8-distributed alignment)
ExcelSheet.ActiveSheet.Cells(row,col).VerticalAlignment = 2;
//Vertical alignment enumeration* (1-top, 2-center, 3-bottom, 4-aligned at both ends, 5-dispersed alignment)
Rows and columns have corresponding operations:
ExcelSheet. ActiveSheet.Rows(row).
ExcelSheet.ActiveSheet.Columns(col).
ExcelSheet.ActiveSheet.Rows(startrow ":" endrow).
//Such as Rows("1:5" ) that is Rows 1 to 5
ExcelSheet.ActiveSheet.Columns(startcol ":" endcol).
//For example, Columns("1:5"), that is, the area of ​​columns 1 to 5
has corresponding operations:
XLObj.Range(startcell ":" endcell).Select;
//For example, Range("A2:H8" ) is the entire area from the 2nd cell in column A to the 8th cell in column H
XLObj.Selection.
Merge cells
The entire range is merged into one cell
Columns(startcol ":" endcol).ColumnWidth = 22;
//Set the width of the column from firstcol to stopcol to 22
ExcelSheet.ActiveSheet.Rows(startrow ":" endrow).RowHeight = 22;
//Set the width of the rows from firstrow to stoprow to 22
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn