This article tells you a C# script that can be used to automatically open PPT files, and then continue to perform page flipping. Screens are taken every time you turn the page. Automatically close PPT after page turning and reopen it
Recently, I found that the plug-in for Office will gg at a certain number of page flips, so I wrote such a script, which can be used by small partners.
Compile the following code, then put several PPTX files that need to be tested in the same folder of the compiled program. Double-click to run the program to test.
class Program { static void Main(string[] args) { var guid = Guid.NewGuid().ToString("N"); for (int i = 1; i <= 10000; i++) { Process p = new Process(); //Set up the application to start p.StartInfo.FileName = "cmd.exe"; //Whether to start using operating system shell p.StartInfo.UseShellExecute = false; // Accept input from the caller p.StartInfo.RedirectStandardInput = true; //Output information p.StartInfo.RedirectStandardOutput = true; // Output error p.StartInfo.RedirectStandardError = true; //Do not display program window p.StartInfo.CreateNoWindow = true; Thread.Sleep(2000); var directory = new DirectoryInfo($"The first{i}second {guid}"); directory.Create(); string pptFile = GetPPT(); Console.WriteLine("Start file: " + pptFile); Console.WriteLine(@"The first " + i + " Secondary startup:"); p.Start(); //Send input information to the cmd window Thread.Sleep(2000); p.StandardInput.WriteLine("\"" + pptFile + "\""); p.StandardInput.AutoFlush = true; Console.WriteLine(@"Start the client"); Thread.Sleep(10000); //Trigger F5 key keybd_event(116, 0, 0, 0); // How many pages do you turn? for (int j = 1; j < 10; j++) { Thread.Sleep(2000); keybd_event(vbKeyDown, 0, 0, 0); Console.WriteLine(@"Start turning pages"); // Turn over a screenshot // By CopyFromScreen method of Graphics, the full-screen image is copied into a blank image of the same size as the screen. // When the copy is complete, CatchBmp is a copy of the full-screen image, and then designates it as the background image of the screenshot form. // Create a new image the same size as the screen Bitmap CatchBmp = new Bitmap(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height); // Create a drawing board so that we can draw on it. // The drawing board is the same size as the screen. // We can use the Graphics class to draw pictures on this blank picture. Graphics g = Graphics.FromImage(CatchBmp); // Copy the screen image to the blank image CatchBmp we created g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height)); var file = new FileInfo(Path.Combine(directory.FullName, $"{j}.png")); var fileStream = new FileStream(file.FullName, FileMode.Create, FileAccess.Write); using (fileStream) { CatchBmp.Save(fileStream, ImageFormat.Png); CatchBmp.Dispose(); } Console.WriteLine("Save Screenshot" + file.FullName); } Thread.Sleep(2000); keybd_event(18, 0, 0, 0); keybd_event(115, 0, 0, 0); keybd_event(18, 0, 2, 0); keybd_event(115, 0, 2, 0); Thread.Sleep(2000); Console.WriteLine("kill"); foreach (var temp in Process.GetProcesses()) { try { if (temp.ProcessName.IndexOf("power", StringComparison.InvariantCultureIgnoreCase) >= 0) { temp.Kill(); } } catch (Exception e) { Console.WriteLine(e); } } p.Kill(); } } private static string GetPPT() { var directory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); var list = directory.GetFiles("*.pptx").ToList(); return list[_random.Next(list.Count)].FullName; } private static readonly Random _random = new Random(); [DllImport("user32.dll")] public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo); public const byte vbKeyDown = 0x28; // DOWN ARROW key }
After running this script for a few days, I went to see the screenshot and found that when I turned to a certain page, my plug-in was gg. After I repaired it, I ran the script again and found that there was no gg, so I could tell Microsoft that I repaired my plug-in and uploaded it again.
How to write Office plug-ins and recommend Chen Xizhang's Office 365 Development Overview Series
I set up my own blog https://blog.lindexi.com/ Welcome to visit, there are many new blogs. Only when I see blogs mature will they be placed in csdn or blog park, but once they are published, they will not be updated.
If you see anything in your blog that you don't understand, welcome to communicate. I built it. dotnet Vocational and Technical College Welcome to join us
This work adopts Knowledge Sharing Signature - Noncommercial Use - Sharing 4.0 International Licensing Agreement in the Same Way License. Reprint, use and redistribute are welcome, but the article signature must be retained. Lin Dexi (Contains links: http://blog.csdn.net/lindexi_gd) and may not be used for commercial purposes. Work modified in this article must be released under the same license. If you have any questions, please contact me. contact.