WPS Header and footer operation tips

Source: Internet
Author: User
Tags mongodb postgresql redis firewall



1. Introduction

In the daily WPS text Two development, often involves the operation of headers and footers. such as: Add, delete, modify text, graphics, and images in headers and footers,



This article through the WPS text provides two development interfaces, based on WPS, while taking into account word to introduce the usage.



Note: WPS is very similar to Word, but it has its own characteristics.



2. Introduction


When you set up headers and footers, you might relate to knowledge of page setup and fields. 



2.1. Section, Page Setup, page Number field


Section: Typically, the next object in the document is a section (that is, application->documents->sections), and headers and footers can be set differently in different sections.



Page Setup:



Different odd and even pages: This feature makes it easy to set "headers and footers" like books, such as dictionaries.



Home different: This feature for the convenience of setting the homepage for the cover and set. (note: Usually the cover does not show page numbers)



Fields: If the page Number field is inserted in the header and footer (that is, if you do the following: Insert, page number, so that the inserted page number is a field, and, in the input page is the same field), the page number of each sheet will change according to the current page.



2.2. Read the header and footer contents


The following is a header to introduce, the footer as long as the headers changed to footers can be, other knowledge exactly the same.



The usual approach is:



Activedocument.sections (1). Headers (wpsheaderfooterprimary). Range.Text



Note: The wpsheaderfooterprimary here can get the enumeration values and describe the following:



Name Value Description



Wpsheaderfooterevenpages 3 Returns all headers or footers on even pages



Wpsheaderfooterfirstpage 2 Returns the first header or footer in a document or section



Wpsheaderfooterprimary 1 Returns a header or footer on all pages except the first page in a document or section



For page setup, the content in the read header is broken down as follows:



2.2.1. "Odd and even pages are selected in Page Setup"


Read the contents of even pages:



Activedocument.sections (1). Headers (wpsheaderfooterevenpages). Range.Text



Read the contents of odd pages:



You can use:



Activedocument.sections (1). Headers (wpsheaderfooterprimary). Range.Text



Attention:



If a dynamic content is set in the header, as in the page ("*" is a number that is automatically updated based on the page number), the content reads:



Here's the difference with Word:



1. Word: is based on the position of the current cursor (such as: the cursor on page 2nd, then wdheaderfooterevenpages read the page 2nd header content, if on the 4th page, read the content of the 4th page, if the cursor on the 3rd page, then read what is sometimes 2 pages, Sometimes it is 4 pages, the law does not elaborate.



2. WPS: Read the first matching header (for example: Wpsheaderfooterevenpages reads the content of page 2nd; Wpsheaderfooterprimary is the content of page 1th or 3rd).



2.2.2. In the page setup, check the "first page is different"


Read the contents of the first page:



Activedocument.sections (1). Headers (Wpsheaderfooterfirstpage). Range.Text



Read content except the first page:



Activedocument.sections (1). Headers (wpsheaderfooterprimary). Range.Text



2.3. Delete, modify the contents of the header


Similar to the above, usually used (in other cases, refer to the above method):



Activedocument.sections (1). Headers (wpsheaderfooterprimary). range.text= "KingSoft"



3. Manipulate the graphic or image in the header





3.1. Read the graphic or image in the header


Read all the shapes in the header and footer (no inline pictures included):



Activedocument.sections (1). Headers (wpsheaderfooterprimary). Shapes.count



can also be used: Wpsheaderfooterfirstpage, Wpsheaderfooterevenpages here three read out the same results.



Read the graphic in the header in the page Setup with "Different first page" (No inline picture included):



Activedocument.sections (1). Headers (Wpsheaderfooterfirstpage). Range.ShapeRange.Count



Other even pages are similar.



Attention:



Most situations should be used. Range.ShapeRange.Count to manipulate graphics.



3.2. Add a graphic to the header and align Left


Attention:



The following code is for demonstration purposes only and does not bear any responsibility for any problems that may exist.



To run the following code, you must meet two files:



1. Assuming that there are c:tempafter.gif documents;



2. You can switch to the header and footer once, that is, there is already a header and footer information, that is, at least one carriage return, (Word does not need this condition).



Example code 1: ' Add a picture to the left alignment in the header



Sub Addpicturetoheadertoleft ()



Dim Myleft, Mytop



Myleft = activedocument.sections (1). PageSetup.LeftMargin



Mytop = activedocument.sections (1). Pagesetup.headerdistance



Activedocument.sections (1). Headers (wpsheaderfooterprimary). Shapes.addpicture _



"C:tempafter.gif", Left:=myleft, Top:=mytop



End Sub



Example code 2: ' Add a picture to the header and align to the right



Sub Addpicturetoheadertoright ()



Dim Myleft, Mytop



Dim Tempshape as Shape



Mytop = activedocument.sections (1). Pagesetup.headerdistance



Myleft = activedocument.sections (1). Pagesetup.pagewidth-activedocument.sections (1). Pagesetup.rightmargin



Set Tempshape = activedocument.sections (1). Headers (wpsheaderfooterprimary). Shapes.addpicture _



("C:tempafter.gif", Left:=myleft, Top:=mytop)



Tempshape. left = Tempshape. Left-tempshape. Width



End Sub



Example code 3: ' Add a picture to the header and align to the right



Sub Addpicturetofootertoleft ()



Dim Myleft, Mytop



Myleft = activedocument.sections (1). PageSetup.LeftMargin



Mytop = activedocument.sections (1). Pagesetup.pageheight-activedocument.sections (1). Pagesetup.bottommargin



Mytop = Mytop + (activedocument.sections (1). Pagesetup.bottommargin-activedocument.sections (1). Pagesetup.footerdistance)



Mytop = mytop-11



Activedocument.sections (1). Footers (wpsheaderfooterprimary). Shapes.addpicture _



"C:tempafter.gif", Left:=myleft, Top:=mytop



End Sub



4. Matters needing attention


1. If you insert a page number in the form of Insert, page number, and when you enter a view from view, header, and footer, the cursor defaults to the frame of the page number, which may affect the user editing the header and footer through the API switch view.



2. When inserting a graphic in a header and footer (including the body), the order of the ShapeRange is different from the order of the shapes.



You should usually use the shapes to take the last inserted graphic:



Activedocument.sections (1). Headers (wpsheaderfooterprimary). Shapes (Activedocument.sections (1). Headers (wpsheaderfooterprimary). Shapes.count). Select


5. For reference



For more API operations, see the WPS API help documentation.


6. Scope of application



Available for WPS Office 2009 (1705) versions


Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

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.