Knowledgebase (2344)
Children categories
At some point, programmers may need to determine if an Excel file contains VBA macros. This article is going to show you how to programmatically determine if an Excel file contains VBA macros in C# and VB.NET using Spire.XLS.
Detail steps:
Step 1: Instantiate a Workbook object and load the Excel file.
Workbook workbook = new Workbook();
workbook.LoadFromFile("Macro.xlsm");
Step 2: Determine if the Excel file contains VBA macros.
bool hasMacros = false;
hasMacros = workbook.HasMacros;
if (hasMacros)
{
Console.WriteLine("The file contains VBA macros");
}
else
{
Console.WriteLine("The file doesn't contain VBA macros");
}
Screenshot:

Full code:
using System;
using Spire.Xls;
namespace Determine_if_Excel_file_contains_macros
{
class Program
{
static void Main(string[] args)
{
//Instantiate a Workbook object
Workbook workbook = new Workbook();
//Load the Excel file
workbook.LoadFromFile("Macro.xlsm");
bool hasMacros = false;
//Determine if the Excel file contains VBA macros
hasMacros = workbook.HasMacros;
if (hasMacros)
{
Console.WriteLine("The file contains VBA macros");
}
else
{
Console.WriteLine("The file doesn't contain VBA macros");
}
Console.ReadKey();
}
}
}
Imports System
Imports Spire.Xls
Namespace Determine_if_Excel_file_contains_macros
Class Program
Private Shared Sub Main(ByVal args As String())
Dim workbook As Workbook = New Workbook()
workbook.LoadFromFile("Macro.xlsm")
Dim hasMacros As Boolean = False
hasMacros = workbook.HasMacros
If hasMacros Then
Console.WriteLine("The file contains VBA macros")
Else
Console.WriteLine("The file doesn't contain VBA macros")
End If
Console.ReadKey()
End Sub
End Class
End Namespace
Adding footers to a PDF document is a useful way to provide additional information and context to the content within the document. Footers typically appear at the bottom of each page and can include elements such as page numbers, dates, copyright information, or any other relevant details. By incorporating footers, you can enhance the professionalism and organization of your PDF files, making them more informative and easier to navigate for readers. In this article, you will learn how to add a footer to an existing PDF document in C# and VB.NET using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLLs included in the Spire.PDF for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Background Knowledge
When an existing PDF document is manipulated by Spire.PDF for .NET, the origin of the coordinate system is located at the top left corner of the page, with the x-axis extending to the right and the y-axis extending downward. Adding a footer to a page means adding content, such as text, images, automatic fields and shapes, to a specified location in the bottom blank area of the page.

If the blank area is not large enough to accommodate the content you want to add, you can consider increasing the PDF page margins.
Add a Footer to an Existing PDF Document in C#, VB.NET
Spire.PDF for .NET offers the PdfCanvas.DrawString() method, PdfCanvas.DrawImage() method, PdfCanvas.DrawLine() method and its similar methods, allowing users to draw text, images and shapes on a PDF page at the specified location. To add dynamic data to the footer, such as page numbers, sections, dates, you need to use the automatic fields. Spire.PDF for .NET provides the PdfPageNumberField class, PdfPageCountField calss, PdfSectionNumberField class etc. to achieve the addition of dynamic information.
The following are the steps to add a footer consisting of an image and page number to a PDF document using Spire.PDF for .NET.
- Create a PdfDocument object.
- Load a PDF document using PdfDocument.LoadFromFile() method.
- Load an image using PdfImage.FromFile() method.
- Draw the image on the bottom blank area of a page using PdfPageBase.Canvas.DrawImage() method.
- Create a PdfPageNumberField object, a PdfPageCountField object, and combine them in a PdfCompositefield object to return the string "Page X of Y".
- Draw page number on the bottom blank area of a page using PdfCompositeField.Draw() method.
- Save the document to another PDF file using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.AutomaticFields;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace AddHeaderToExistingPdf
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");
//Load an image
PdfImage footerImage = PdfImage.FromFile("C:\\Users\\Administrator\\Desktop\\bg.jpg");
//Create a true type font
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Times New Roman", 12f, FontStyle.Bold), true);
//Create a brush
PdfBrush brush = PdfBrushes.White;
//Create a page number field
PdfPageNumberField pageNumberField = new PdfPageNumberField();
//Create a page count field
PdfPageCountField pageCountField = new PdfPageCountField();
//Create a composite field to combine page count field and page number field in a single string
PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumberField, pageCountField);
//Get the text size
SizeF fontSize = font.MeasureString(compositeField.Text);
//Get the page size
SizeF pageSize = doc.Pages[0].Size;
//Set the position of the composite field
compositeField.Location = new Point((int)(pageSize.Width - fontSize.Width) / 2, (int)pageSize.Height - 45);
//Loop through the pages in the document
for (int i = 0; i < doc.Pages.Count; i++)
{
//Get a specific page
PdfPageBase page = doc.Pages[i];
//Draw the image on the bottom blank area
page.Canvas.DrawImage(footerImage, 55, pageSize.Height - 65, pageSize.Width - 110, 50);
//Draw the composite field on the bottom blank area
compositeField.Draw(page.Canvas);
}
//Save to file
doc.SaveToFile("AddFooter.pdf");
doc.Dispose();
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Spire.XLS supports to hide or unhide certain shapes in Excel worksheet through IShape.Visible property. This article demonstrates the detail steps to hide or unhide a shape using Spire.XLS and C#.
Below is the screenshot of the example Excel file:

Detail steps:
Step 1: Instantiate a Workbook object and load the Excel file.
Workbook workbook = new Workbook();
workbook.LoadFromFile("Input.xlsx");
Step 2: Get the first worksheet.
Worksheet sheet = workbook.Worksheets[0];
Step 3: Hide the second shape in the worksheet.
//Hide the second shape in the worksheet sheet.PrstGeomShapes[1].Visible = false; //Show the second shape in the worksheet //sheet.PrstGeomShapes[1].Visible = true;
Step 4: Save the file.
workbook.SaveToFile("HideShape.xlsx", ExcelVersion.Version2013);
Output:

Full code:
using Spire.Xls;
namespace HideShape
{
class Program
{
static void Main(string[] args)
{
//Instantiate a Workbook object
Workbook workbook = new Workbook();
//Load the Excel file
workbook.LoadFromFile("Input.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Hide the second shape in the worksheet
sheet.PrstGeomShapes[1].Visible = false;
//Show the second shape in the worksheet
sheet.PrstGeomShapes[1].Visible = true;
//Save the file
workbook.SaveToFile("HideShape.xlsx", ExcelVersion.Version2013);
}
}
}