ASP operation Excel technology summary

xiaoxiao2021-03-06  102

ASP operation Excel technology summary

table of Contents

First, environmental configuration

Second, ASP's basic operation of Excel

Third, ASP operation Excel generates data sheet

Fourth, ASP operation Excel generates chart

V. Server EXCEL file browsing, download, delete scheme

6. Appendix

text

First, environmental configuration

The server-side environment configuration looks on the reference, the Microsoft series should be all line, namely:

1. Win9X PWS Office

2. Win2000 Professional PWS Office

3. Win2000 Server IIS Office

At present, the author's successful environment is the last two. The version of Office does not have special requirements, take into account the uncertainty and compatibility features of client configuration, and it is recommended that the server-side Office version should not be too high to prevent the client from being downloaded after downloading.

There are two accidental discovery of server-side environment configurations:

1. The author develops the machine's original WPS2002, and the results of the Excel object have always been issued, and after uninstalling the WPS2002, the error disappears.

2. The author develops ASP code likes to use FrontPage, and the results are found to find that if the FrontPage is open (server-side), the object creates unstable phenomenon, and it is time to succeed. After the expansion, found that the Office series software is running in the server side, and the creation of the Excel object is difficult to succeed.

The server side must also set is the operation permission of the COM component. Type "DCMCNFG" on the command line, enter the COM component configuration interface. After selecting Microsoft Excel, click the Properties button to select a custom, and the EVERYONE is added to all permissions. Restart the server after saving.

The client's environmental configuration did not find anything particularly parallel, as long as office and IE can be installed, the version is generally like.

Second, ASP's basic operation of Excel

1. Create an Excel object

Set objexcelapp = createObject ("excel.application")

Objexcelapp.displayalerts = false does not display a warning

Objexcelapp.Application.visible = false does not display interface

2, create an Excel file

Objexcelapp.workbooks.add

Set ObjexcelBook = Objexcelapp.activeWorkbook

Set objexcelsheets = ObjexcelBook.Worksheets

Set objexcelsheet = ObjexcelBook.sheets (1)

3, read excel files

straddr = Server.mappath (".")

Objexcelapp.workbooks.open (straddr & "/templet/table.xls")

Set ObjexcelBook = Objexcelapp.activeWorkbook

Set objexcelsheets = ObjexcelBook.Worksheets

Set objexcelsheet = ObjexcelBook.sheets (1)

4. Save an Excel file

Objexcelbook.saveas straddr & "/temp/table.xls"

5, save the Excel file

Objexcelbook.save (the author is saved, the page is wrong.) 6, exit Excel operation

Objexcelapp.quit must exit

Set objexcelapp = Nothing

Third, ASP operation Excel generates data sheet

1, insert data within one range

Objexcelsheet.Range ("B3: K3"). Value = Array ("67", "87", "5", "9", "7", "45", "45", "54", "54" , "10")

2, insert data in one unit

Objexcelsheet.cells (3, 1) .value = "Internet Explorer"

3, select a range

4, the thick line of the cell

5, the unit grown on the right side of the coarse line

6, the thick line of painting on the cell

7, drawing thick lines at the lower cell

8, cell setting background color

9, combined unit

10, insert

11, insert column

Fourth, ASP operation Excel generates chart

1, create a chart map

Objexcelapp.Charts.add

2, set the type of Chart map

Objexcelapp.activechart.ChartType = 97

Note: Two-dimensional line diagram, 4; two-dimensional cake, 5; two-dimensional column, 51

3, set the chart figure title

Objexcelapp.activechart.hastitle = true

Objexcelapp.activechart.charttitle.text = "a test chart"

4, set graphics through table data

Objexcelapp.activechart.setsourceData Objexcelsheet.Range ("A1: K5"), 1

5, set the graphic data directly (recommended)

Objexcelapp.activechart.seriescollection.newseries

Objexcelapp.activechart.seriescollection (1) .Name = "=" "333" ""

Objexcelapp.activechart.seriescollection (1) .values ​​= "= {1,4,5,6,2}"

6, binding Chart chart

Objexcelapp.activechart.Location 1

7, display data table

Objexcelapp.activeChart.hasDataTable = TRUE

8, display legend

Objexcelapp.activechart.DataTable.showlegendKey = True

V. Server EXCEL file browsing, download, delete scheme

Browse the solution, "location.href =", "navigate", "response.redirect" can be implemented, recommended for client-side methods, because more time to generate an Excel file for more time.

The implementation of the download is troublesome. Downloading components on an online homeD server or custom development a component is a better solution. Another method is to operate the Excel component at the client, and save the server-side EXCEL file to the client. This approach requires the client to open an operation permission of unsafe ActiveX controls, considering that each customer sets the server set to trusted sites, it is more expensive to use the first method.

The deletion scheme consists of three parts:

A: The Excel file generated by the same user is confident that the string is confident by the same file name, the file name. This automatically overrides the previous file when the new file is generated. B: Set the SESSION_ONEND event in the global.asa file to delete the user's Excel temporary file.

C: When setting the Application_onstart event in the global.asa file, delete all the files in the temporary directory.

Note: Recommended Directory Structure / SRC Code / Templet Template Directory / TEMP Temporary Directory

6. Appendix

At the time of error, the death process of Excel appeared was a very headache. Plus "On Error Resume next" before each file will help improve this, because it will execute it to "Application.quit" regardless of whether the file generates an error, guarantees that each program is not left process.

Supplement two points:

1. Other Excel specific operations can be solved by recording macros.

2, 2, the server-side open SQL Enterprise Manager will also generate problems.

Seven, example

<%

ON Error ResMe next

straddr = Server.mappath (".")

Set objexcelapp = createObject ("excel.application")

Objexcelapp.displayAlerts = false

Objexcelapp.Application.visible = false

Objexcelapp.workbooks.open (straddr & "/templet/null.xls")

Set ObjexcelBook = Objexcelapp.activeWorkbook

Set objexcelsheets = ObjexcelBook.Worksheets

Set objexcelsheet = ObjexcelBook.sheets (1)

Objexcelsheet.Range ("B2: K2"). Value = Array ("Week1", "Week2", "Week3", "Week4", "Week5", "WEEK6", "Week7", "Week", "Week9" , "Week10")

Objexcelsheet.Range ("B3: K3"). Value = Array ("67", "87", "5", "9", "7", "45", "45", "54", "54" , "10")

Objexcelsheet.Range ("B4: K4"). Value = Array ("10", "10", "8", "27", "33", "37", "50", "54", "10" , "10")

Objexcelsheet.Range ("B5: K5"). Value = Array ("23", "3", "86", "64", "60", "18", "5", "1", "36" , "80") Objexcelsheet.cells (3, 1) .value = "Internet Explorer"

Objexcelsheet.cells (4, 1) .value = "Netscape"

Objexcelsheet.cells (5, 1) .value = "ER"

Objexcelsheet.Range ("B2: K5"). SELECT

Objexcelapp.Charts.add

Objexcelapp.activechart.ChartType = 97

Objexcelapp.activeChart.barshape = 3

Objexcelapp.activechart.hastitle = true

Objexcelapp.activechart.charttitle.text = "Visitors Log for Each Week Shown in Browsers Percentage"

Objexcelapp.activechart.setsourceData Objexcelsheet.Range ("A1: K5"), 1

Objexcelapp.activechart.Location 1

'Objexcelapp.activeChart.hasDataTable = TRUE

'Objexcelapp.ActiveChart.DataTable.ShowleGendKey = TRUE

Objexcelbook.saveas straddr & "/temp/excel.xls"

Objexcelapp.quit

Set objexcelapp = Nothing

%>

3C

// DTD HTML 4.0 Transitional // En ">

new document </ title></p> <p><</p> <p>Meta</p> <p>Name = "generator" Content = "Microsoft FrontPage 5.0"></p> <p><</p> <p>Meta</p> <p>Name = "Author" content = ">"></p> <p><</p> <p>Meta</p> <p>Name = "Keywords" Content = ">"></p> <p><</p> <p>Meta</p> <p>Name = "Description" content = ">"></p> <p></ HEAD></p> <p><Body></p> <p></ Body></p> <p></ Html></p> <p>I am later here. Way the form and save the web page.</p> <p>For example: Table ID = MyTable</p> <p><! - Generate an Excel file -></p> <p>SUB BTNEXPORT_ONCLICK ()</p> <p>Dim Objexcel</p> <p>ON Error ResMe next</p> <p>Set objexcel = createObject ("excel.application")</p> <p>With objexcel.visible = TRUE</p> <p>.workbooks.add</p> <p>. Sheets ("Sheet1"). SELECT</p> <p>End with</p> <p>m_row = "0"</p> <p>For a = 0 to Document.all.Mytable.Rows.Length-1</p> <p>m_row = cstr (int (m_row) 1)</p> <p>For b = 0 to Document.all.mytable.Rows (a) .Cells.Length-1</p> <p>m_col = chr (ASC ("a") b)</p> <p>Objexcel.Range (m_col & m_row) .select</p> <p>M_value = document.all.mytable.Rows (a) .Cells (b) .innertext</p> <p>Objexcel.activecell.Value = cstr (m_value)</p> <p>NEXT</p> <p>NEXT</p> <p>Objexcel.visible = TRUE</p> <p>Objexcel.Range ("a1"). SELECT</p> <p>End Sub</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-124487.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="124487" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.033</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'd0PbH8FPRoxjPzT0DBWw4K_2F7oqMyPfG7_2FsoL1Azuin3Wz72cTTseLi7_2BoWUOyiaHIGck0r_2BM_2BaR7cdX0zDmHXw_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>