Export scripts to excel

Source: Internet
Author: User

Replace theseCodeThe slave is always excel.htm "(cannot run on csdn)

========================================================== ==========

ASP

<P>

<%

Response. contenttype = "application/vnd. MS-excel"

%>

</P>

VBScript:

<P>

<Input type = "button" onclick = "VBScript: startexcel ()" value = "vbscript1"/>

<Input type = "button" onclick = "VBScript: startexcel2 ()" value = "vbscript2"/>

</P>

Javascript:

<P>

<Input type = "button" onclick = "javascript: jstartexcel ()" value = "JavaScript"/>

</P>

<P>

<A href = "http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/office97/html/output/F1/D3/s5a341. ASP "target =" _ blank "> Microsoft Excel Language Reference </a>-msdn (recommended !)

</P>

Reference:

<P>

<A href = "http://builder.com.com/5100-6373-5072712.html" target = "_ blank"> always e ways to pass a Microsoft Excel file to the client side

</A>

</P>

<Script language = 'vbscript'>

Dim xcl

Sub startexcel ()

Set xcl = Createobject ("Excel. application ")

Xcl. Visible = true

Set newbook = xcl. workbooks. Add

Newbook. worksheets. Add

Newbook. worksheets (1). Activate

Newbook. worksheets (1). Range ("A1: B1000"). numberformat = "0"

Newbook. worksheets (1). Range ("A1: B1000"). horizontalalignment = 1' left alignment

Newbook. worksheets (1). Range ("A1: d1"). Merge () 'merge Cells

Newbook. worksheets (1). Range ("A1: d1"). value = "test" 'value assignment

Newbook. worksheets (1). Range ("A1: d1"). horizontalalignment = 3' align

Newbook. worksheets (1). Columns ("A"). columnwidth = 50' set the column width

Newbook. worksheets (1). Rows (2). rowheight = 40' set the Row Height

Newbook. worksheets (1). Columns ("A"). wraptext = true

Newbook. worksheets (1). Columns ("B"). columnwidth = 50

Newbook. worksheets (1). Columns ("B"). wraptext = true

Newbook. worksheets (1). cells (). Interior. colorindex = "15" 'set the color of the word

Newbook. worksheets (1). cells (). Borders. linestyle = 1' set border 1 to solid line, and 2 to dotted line

Newbook. worksheets (1). cells (3, 2). Font. Name = "verdana"

Newbook. worksheets (1). cells (3, 2). Font. italic = true

Newbook. worksheets (1). cells (3, 2). horizontalalignment = 4' right alignment

Newbook. worksheets (1). cells (2, 1). value = "first column, first cell"

Newbook. worksheets (1). cells (3, 1). value = "first column, second cell"

Newbook. worksheets (1). cells (2, 2). value = "second column, first cell"

Newbook. worksheets (1). cells (3, 2). value = "seond column, second cell"

Newbook. worksheets (1). Name = "My first worksheet"

'Fname = xcl. getsaveasfilename ("testing Excel extraction.xls ")

'If fname = "false" then

'Fname = ""

'End if

The 'newbook. saveas fname' file is automatically saved as testing Excel extracting.xls

'Xcl. application. quit' close Excel

Set xcl = nothing

End sub

sub startexcel2 ()
set xcl = Createobject ("Excel. application ")
xcl. visible = true
set newbook = xcl. workbooks. add a new worksheet
newbook. worksheets (1 ). activate
newbook. worksheets (1 ). range ("A1: B1000 "). numberformat = "0"
newbook. worksheets (1 ). cells (1, 1 ). value = "value1"
newbook. worksheets (1 ). cells (2, 1 ). value = "value2"
newbook. worksheets (1 ). cells (1, 2 ). value = "20"
newbook. worksheets (1 ). cells (2, 2 ). value = "10"
newbook. worksheets (1 ). cells (3, 1 ). value = "Total"
newbook. worksheets (1 ). cells (3, 2 ). value = "= sum (B1: B2)"
newbook. worksheets (1 ). cells (4, 1 ). value = CINT (newbook. worksheets (1 ). cells (3, 2 ). value * 2)
newbook. worksheets (1 ). name = "my second worksheet" 'worksheet name
'xcl. application. quit' close Excel
set xcl = nothing
end sub

Function jstartexcel (){

VaR XLS = new activexobject ("Excel. application ");

XLS. Visible = true;

VaR newbook = XLS. workbooks. Add;

Newbook. worksheets. Add;

Newbook. worksheets (1). Activate;

XLS. activeworkbook. activesheet. pagesetup. Orientation = 2;

XLS. activeworkbook. activesheet. pagesetup. papersize = 5;

Newbook. worksheets (1). Columns ("A"). columnwidth = 40; // set the width of column A to 40px.

Newbook. worksheets (1). Columns ("A"). wraptext = true; // set automatic line feed.

Newbook. worksheets (1). Columns ("B"). columnwidth = 50; // set the width of Column B to 50px.

Newbook. worksheets (1). Columns ("B"). wraptext = true; // set automatic line feed.

Newbook. worksheets (1). Range ("A1: B1000"). numberformat = "0 ";

Newbook. worksheets (1). Range ("A1: B1000"). horizontalalignment =-4131;

Newbook. worksheets (1). Range ("A1: B1"). Merge (); // merge the cell area A1: d1

Newbook. worksheets (1). Range ("A1: B1"). value = "my title"; // assign a value

Newbook. worksheets (1). Range ("A1: B1"). horizontalalignment = 3; // align

Newbook. worksheets (1). Range ("A1: B1"). Interior. colorindex = 2; // set the background color to white.

Newbook. worksheets (1). Range ("A1: B1"). Font. Bold = true; // bold

Newbook. worksheets (1). Range ("A1: B1"). Font. colorindex = 3; // The font is red.

Newbook. worksheets (1). cells (2, 1). Interior. colorindex = 15; // background color

Newbook. worksheets (1). cells (2, 1). value = "second row, first column ";

Newbook. worksheets (1). cells (2, 1). Font. italic = true;

Newbook. worksheets (1). cells (2, 1). Font. Bold = true;

Newbook. worksheets (1). cells (2, 2). value = "second row, second column ";

Newbook. worksheets (1). cells (3, 1). value = "third row, first column ";

Newbook. worksheets (1). cells (3, 2). value = "third row, second column ";

Newbook. worksheets (1). Name = "My first worksheet ";

}

</SCRIPT>



Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.