Method and settings generated by an Excel file with C # to create access to access rights using an ASP.NET

xiaoxiao2021-03-05  29

An example:

Class Apptest {Private Excel.ApplicationClass_X; Public Static Void Main0 () {AppTest A = New Apptest (); A._X = New Excel.ApplicationClass (); A._X.UserControl = false; for (int i = 0; i <4; i ) {a.savetoxls ("D: // Test ///" I ".xls"); // This example is the TEST folder established under D._x.quit ( ); System.Runtime.InteropServices.Marshal.releaseComobject ((object) a._x); system.gc.collect ();}

Private void Savetoxls (String FileName) {Excel.WorkbookClass WB = (Excel.WorkbookClass) this._x.Workbooks.Add (System.Reflection.Missing.Value); for (int i = 1; i <= 4; i ) { this._x.cells [i, 1] = i.toString (); this._x.cells [i, 2] = "'bb2"; this._x.cells [i, 3] = "' ccc3"; this ._x.cells [i, 4] = "'aaa4";} wb.saved = true; this._x.activeworkbook.savecopyas (filename);}}

[Note: The Excel component vs.net itself is not available in VS.NET. Office2003 comes with Excel.dll, add Microsoft Excel 11.0 Object Library directly in the Add reference

1. To ensure that the machine itself should install Office.

2. Copy the excel9.olb file under [C: / Program Files / Microsoft Office / Office: Default Mounting Path] to [C: / Visual Studio.net/SDK/v1.1/bin :vs.net Installation Path] Under the path.

3. Open the Visual Studio .Net2003 command prompt, run TLBIMP Excel9.olb Excel.dll, generate an Excel.dll component in [C: / Visual Studio.net/SDK/v1.1/bin].

4. Add an Excel.dll in the project to OK.

[Note: Set the ASP.NET operational access]

Want to use ASP.NET to operate Excel may need to set up two places, the first, the security settings of the properties of the file or folder you want to operate, right click on the directory selection [Properties], select Fourth in the [Properties] dialog box Item [Security], set the access permission of Everyone is Full Control; click the [Add] button to increase the native user [ASPNET], set access to Full Control.

转载请注明原文地址:https://www.9cbs.com/read-33379.html

New Post(0)