Home > database >  Ole in the webform excel operation
Ole in the webform excel operation

Time:09-20

Forwarding, collection to save for future reference
1. The permissions

Start - & gt; Run dcomcnfg. Exe, open as shown in the figure below:

Find the Microsoft Excel Application component, right-click the selection properties,

Select security:

All selected custom, and add the user (demo start and activated permissions only) :



Choose to determine after the iis user, and to give all permissions:

Finally will Microsoft Excel program root folder and all involves security permissions of the file to add the iis user and give full control permissions,

2. The function change

Because pb webform release is first converted into c # code, and then copied to the iis server site, so originally in pb ole operation excel can appear grammar mistakes! The following is a correct code examples:
OLEObject ExcelServer
ExcelServer=CREATE OLEObject
ExcelServer. ConnectToNewObject (" excel. Application ")
ExcelServer. Visible=false (note: no application)
ExcelServer. DisplayAlerts=False
ExcelServer. Workbooks. The add (" F: \ Schneider Electric SA \ Report \ ABC XLSX ") add the file, the equivalent of a mirror abc1. XLSX
ExcelServer. Workbooks. Open (" F: \ Schneider Electric SA \ Report \ ABC XLSX ") to open this file the XLSX
ExcelServer. ActiveSheet. Cells (r, c] value=(r, c)
https://bbs.csdn.net/topics/dw_1.object.data# if defined pbwebform then
? St_7. Text=MapVirtualPath (" F: \ temp. XLSX)//in order to avoid the influence between the user, first to a virtual path
# end if
ExcelServer. ActiveSheet. SaveAs (st_7. Text)//to each session

# if defined pbwebform then
? Downloadfile (" F: \ temp. XLSX ", false)
# end if

ExcelServer. ActiveWorkBook. Close

ExcelServer. Quit
ExcelServer. DisConnectObject ()
Destroy ExcelServer



C # set properties commonly used Excel.

* 1. Create Excel object
Eole=CREATEOBJECT (' Excel. Application ')
* 2. Add a new workbook
Eole. Workbooks. Add
Activate the specified workbook
Eole. WorkSheets (" book "). The Activate

* 3. Set the third worksheet to activate the worksheet
Eole. Worksheets (" sheet1 "). The Activate
* 4. Open the specified workbook
Eole. Workbooks. The add (" E:/E_temp/ABC. XLS ")
* 5. According to Excel window
Eole. Visible=. T.
* 6. Change the Excel title bar
Eole. Caption="VFP application calls the Microsoft Excel"
* 7. To the cell assignment
* eole. Cells (row, column). value=https://bbs.csdn.net/topics/XM (XM) for database field name
Eole. Cells (1, 4). Value='https://bbs.csdn.net/topics/ASDFASDFASDFASDFADSF'
* 8. Sets the width of the specified column (unit: the number of characters)
Eole. ActiveSheet. Columns (1). ColumnWidth=5
* 9. Setting specifies the height (unit: pounds)
Eole. ActiveSheet. Rows (1). RowHeight=1/0.035 & amp; & Set the line height to 1 cm, 0.035 cm 1 pound=
* (set the line height to 1 cm, 1 pound=0.035 cm)
* 10. Insert a page break before line 18
Eole. Worksheets (" Sheet1 "). The Rows (18) PageBreak=1
* 11. In the fourth column before delete page breaks
Eole. ActiveSheet. Columns (4). PageBreak=0
* 12. Specify a border line width (Borders parameters below)
Eole. ActiveSheet. Range (" b3: d3 "). The Borders (2) Weight=3
* 13. Four border lines set the type of the
Eole. ActiveSheet. Range (" b3: d3 "). The Borders (1) graphics.linestyle=1
* (including Borders parameters: 1 - left, 2 - right, 3 -, 4 -, 5 - inclined, 6 - oblique/; Graphics.linestyle
Values: 1 to 7 - fine, 2 - fine, 4 -, 9 - two thin lines)
* 14. Set the header
Eole. ActiveSheet. PageSetup. CenterHeader="statements 1
"* 15. Set the footer
Eole. ActiveSheet. PageSetup. CenterFooter="first page & P
"* 16. Set the header to the top margin is 2 cm
Eole. ActiveSheet. PageSetup. HeaderMargin 2/0.035=
* 17. Set the footer is 3 cm margin for
Eole. ActiveSheet. PageSetup. FooterMargin 3/0.035=
* 18. Set the top margin is 2 cm
Eole. ActiveSheet. PageSetup. TopMargin 2/0.035=
* 19. Set bottom to 4 cm
Eole. ActiveSheet. PageSetup. BottomMargin 4/0.035=
* 20. Set the left margin is 2 cm
Eole. ActiveSheet. PageSetup. LeftMargin 2/0.035=
* 21. Set the right margin is 2 cm
Eole. ActiveSheet. PageSetup. RightMargin 2/0.035=
* 22. Settings page horizontal center
Eole. ActiveSheet. PageSetup. CenterHorizontally=. T.
* 23. Settings page vertical center
Eole. ActiveSheet. PageSetup. CenterVertically=. T.
* 24. Settings page size (1 - narrow line 8? 5? 11 39 - line 14? 11)
Eole. ActiveSheet. PageSetup. PaperSize=1
Can be one of the following XlPaperSize constants (some printers may not support all of these paper sizes).
Constant value meaning;
XlPaperLetter 1 Letter (8-1/2 in. X 11 in.)
XlPaperA3 eight A3 (297 mm x 420 mm)
XlPaperA4 9 A4 (210 mm x 297 mm)
A4 xlPaperA4Small 10 Small (210 mm x 297 mm)
XlPaperA5 11 A5 (148 mm x 210 mm)
XlPaperB4 12 B4 (250 mm x 354 mm)
XlPaperB5 13 B5 (182 mm x 257 mm)
XlPaperFanfoldUS 39 U.S. Standard Fanfold (14-7/8 in. X 11 in.)
XlPaperUser user-defined

* 25. Print cell line
Eole. ActiveSheet. PageSetup. PrintGridlines=. T.
* 26. Copy the entire worksheet
Eole. ActiveSheet. UsedRange. Copy
* 27. Copy the specified area
Eole. ActiveSheet. Range (" A1: E2). Copy
* 28. Paste the
Eole. Worksheets (" sheet2 "). The Activate
Eole. ActiveSheet. Range (" F1 "). The PasteSpecial
* 29. Insert a line before line 2
Eole. ActiveSheet. Rows (2). Insert
* 30. Before the second column inserts a column
Eole. ActiveSheet. The Columns (2). Insert
* 31. Set the font
Eole. ActiveSheet. Cells (2, 1). The Font Name="bold"
* 32. Set the font size
Eole. ActiveSheet. Cells (1, 1). The Font Size=25
* 33. Set the font to italics
Eole. ActiveSheet. Cells (1, 1). The Font. Italic=. T.
* 34. Set a whole column to bold font
Eole. ActiveSheet. Columns (1). The Font, Bold=. T.

35. Merge cells, important!
_ole_excel. Worksheets (" book "). The Range (the Range). The merge & amp; & Scope must specify the start-stop cell, such as "A1: B4
"
Eole. ActiveSheet. Range (" A1: B4 "). The merge & amp; & Merge range specified in the current working table

36. Cancel the merge cells, the inverse operation
_ole_excel. Worksheets (" book "). The Range (the Range). Unmerge

37. Set the formula within the cell (important, generally can be used to calculate the summary, and many functions such as average)
_ole_excel. Cells (row, column). The value="https://bbs.csdn.net/topics/=formula" & amp; & nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related