Home > Software engineering >  Bosses can help you!
Bosses can help you!

Time:11-17

Vba to realize the open web pages, then screenshots, web links from excel spreadsheets, need a batch web link! Bosses know!

CodePudding user response:

You can refer to this article:
https://www.cnblogs.com/snowdream/archive/2011/05/16/get-webpage-snapshot-by-webbrowser-control.html

Through the WebBrowser access to web screenshot
In this paper, through the control of WinForm WebBroswer access web page screenshots, this method can intercept to larger than the screen area of the page screenshots, but for some control Flash or can't get in your web pages to the image, because is WinForm controls, so did not test in the WPF,

On the interface add a text box and a button, text box for entering the address, the button press event handling function initializes a WebBrowser and open the web page, but it is not shown on the interface,



Copy the code
1///& lt; Summary>
2///button event handler
3///& lt;/summary>
4///& lt; Param name="sender" & gt;
5///& lt; Param name="e" & gt;
6 private void SaveSnapshot_Click (object sender, EventArgs e)
7 {
8 WebBrowser WebBrowser=new WebBrowser ();//create a WebBrowser
9 webBrowser. ScrollBarsEnabled=false;//hide the scroll bar
10 webBrowser. Navigate (address. Text);//open the web page
11 webBrowser. DocumentCompleted +=new WebBrowserDocumentCompletedEventHandler (webBrowser_DocumentCompleted);//add pages loaded event handler
12}
Copy the code

To capture screenshots in the page load to complete processing functions, adjust the size and save images,



Copy the code
1///& lt; Summary>
2///web page loaded event handler
3///& lt;/summary>
4///& lt; Param name="sender" & gt;
5///& lt; Param name="e" & gt;
6 void webBrowser_DocumentCompleted (object sender, WebBrowserDocumentCompletedEventArgs e)
7 {
8 WebBrowser WebBrowser=(WebBrowser) sender;
9
10/finished/page load to save
11 the if (webBrowser. ReadyState==plete WebBrowserReadyState.Com
12 {
13//web height and width, can also set the
14 int height=webBrowser. Document. Body. ScrollRectangle. Height;
15 int width=webBrowser. Document. Body. ScrollRectangle. Width;
16
17//adjust the height and width of the webBrowser
18 webBrowser. Height=Height;
19 webBrowser. Width=Width;
20
21 Bitmap Bitmap=new Bitmap (width, height);//create the picture of the height and width the same as the web
22 a Rectangle Rectangle=new Rectangle (0, 0, width, height);//painting area
23 webBrowser. DrawToBitmap (bitmap, rectangle);//screenshot
24
25//save picture dialog
26 SaveFileDialog SaveFileDialog=new SaveFileDialog ();
27 saveFileDialog. Filter="JPEG (*.jpg) | *. JPG | PNG (*. PNG) | *. PNG";
28 saveFileDialog. ShowDialog ();
29
30 bitmap. The Save (saveFileDialog. FileName);//save picture
31}
32}
Copy the code


Download the sample (Visual Studio 2010)

Classification: the.net Framework
Tags: c # and the.net Framework
  •  Tags:  
  • VBA
  • Related