Monday, 25 September 2017 06:43

Hide or Show Excel Comments in C#

At some point, you may want to display or hide comments in an Excel document. This article shows you how to hide or show an existing comment in an excel document using Spire.XLS.

Detail steps:

Step 1: Instantiate a Workbook instance and load the excel document.

Workbook workbook = new Workbook();
workbook.LoadFromFile("Comments.xlsx");

Step 2: Get the first worksheet.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Hide or show the specific comment in the worksheet.

//Hide comment
sheet.Comments[0].IsVisible = false;

//Show comment
//sheet.Comments[0].IsVisible = true;

Step 4: Save the document.

workbook.SaveToFile("HideComment.xlsx", ExcelVersion.Version2013);

Screenshot:

Hide or Show Excel Comments in C#

Full code:

//Instantiate a Workbook instance and load the excel document
Workbook workbook = new Workbook();
workbook.LoadFromFile("Comments.xlsx");

//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];

//Hide the specific comment in the worksheet
sheet.Comments[0].IsVisible = false;

//Show the specific comment in the worksheet
//sheet.Comments[0].IsVisible = true;

//Save the document
workbook.SaveToFile("HideComment.xlsx", ExcelVersion.Version2013);

You may sometimes want your text to display vertically (letters stacked one on top of the other), horizontally, or rotated facing the right margin or the left margin. This tutorial shows you how to change the text direction using VerticalTextType property in Spire.Presentation.

Step 1: Initialize an instance of Prensentation class.

Presentation ppt = new Presentation();

Step 2: Append a shape with text to the first slide.

IAutoShape textboxShape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 100, 400));
textboxShape.ShapeStyle.LineColor.Color = Color.Transparent;
textboxShape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
textboxShape.Fill.SolidColor.Color = Color.OrangeRed;
textboxShape.TextFrame.Text = "You Are Welcome Here";

Step 3: Set the text direction to vertical.

textboxShape.TextFrame.VerticalTextType = VerticalTextType.Vertical;

Step 4: Append another shape with text to the slide.

textboxShape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(150, 70, 100, 400));
textboxShape.ShapeStyle.LineColor.Color = Color.Transparent;
textboxShape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
textboxShape.Fill.SolidColor.Color = Color.Orange;
textboxShape.TextFrame.Text = "欢迎光临";

Step 5: For asian characters, you can set the VerticalTextType as EastAsianVertical to aviod rotating text 90 degrees.

textboxShape.TextFrame.VerticalTextType = VerticalTextType.EastAsianVertical;

Step 6: Save the file.

ppt.SaveToFile("output.pptx", FileFormat.Pptx2013);

Output:

How to Change Text Direction in PowerPoint in C#, VB.NET

Full Code:

[C#]
Presentation ppt = new Presentation();

IAutoShape textboxShape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 100, 400));
textboxShape.ShapeStyle.LineColor.Color = Color.Transparent;
textboxShape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
textboxShape.Fill.SolidColor.Color = Color.OrangeRed;
textboxShape.TextFrame.Text = "You Are Welcome Here";
textboxShape.TextFrame.VerticalTextType = VerticalTextType.Vertical;

textboxShape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(150, 70, 100, 400));
textboxShape.ShapeStyle.LineColor.Color = Color.Transparent;
textboxShape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
textboxShape.Fill.SolidColor.Color = Color.Orange;
textboxShape.TextFrame.Text = "欢迎光临";
textboxShape.TextFrame.VerticalTextType = VerticalTextType.EastAsianVertical;

ppt.SaveToFile("output.pptx", FileFormat.Pptx2013);
[VB.NET]
Dim ppt As New Presentation()

Dim textboxShape As IAutoShape = ppt.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(50, 70, 100, 400))
textboxShape.ShapeStyle.LineColor.Color = Color.Transparent
textboxShape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid
textboxShape.Fill.SolidColor.Color = Color.OrangeRed
textboxShape.TextFrame.Text = "You Are Welcome Here"
textboxShape.TextFrame.VerticalTextType = VerticalTextType.Vertical

textboxShape = ppt.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(150, 70, 100, 400))
textboxShape.ShapeStyle.LineColor.Color = Color.Transparent
textboxShape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid
textboxShape.Fill.SolidColor.Color = Color.Orange
textboxShape.TextFrame.Text = "欢迎光临"
textboxShape.TextFrame.VerticalTextType = VerticalTextType.EastAsianVertical

ppt.SaveToFile("output.pptx", FileFormat.Pptx2013)
Tuesday, 19 September 2017 08:35

How to toggle the visibility of PDF layer in C#

We have already demonstrated how to use Spire.PDF to add multiple layers to PDF file and delete layer in PDF in C#. We can also toggle the visibility of a PDF layer while creating a new page layer with the help of Spire.PDF. In this section, we're going to demonstrate how to toggle the visibility of layers in new PDF document in C#.

Step 1: Create a new PDF document and add a new page to the PDF document.

PdfDocument pdf = new PdfDocument();
PdfPageBase page = pdf.Pages.Add();

Step 2: Add a layer named "Blue line" to the PDF page and set the layer invisible.

PdfPageLayer layer = page.PageLayers.Add("Blue line", false);
layer.Graphics.DrawLine(new PdfPen(PdfBrushes.Blue, 1), new PointF(0, 30), new PointF(300, 30));

Step 3: Add a layer named "Ellipse" to the PDF page and set the layer visible.

layer = page.PageLayers.Add("Ellipse", true);
PdfPen pen = new PdfPen(Color.Green, 1f);
PdfBrush brush = new PdfSolidBrush(Color.Green);
layer.Graphics.DrawEllipse(pen, brush, 50, 70, 200, 60);

Step 4: Save the document to file.

pdf.SaveToFile("LayerVisibility.pdf", FileFormat.PDF);

Effective screenshot after toggle the visibility of PDF layer:

How to toggle the visibility of PDF layer in C#

Full codes:

static void Main(string[] args)
{

    PdfDocument pdf = new PdfDocument();
    PdfPageBase page = pdf.Pages.Add();

    PdfPageLayer layer = page.PageLayers.Add("Blue line", false);
    layer.Graphics.DrawLine(new PdfPen(PdfBrushes.Blue, 1), new PointF(0, 30), new PointF(300, 30));

    layer = page.PageLayers.Add("Ellipse", true);
    PdfPen pen = new PdfPen(Color.Green, 1f);
    PdfBrush brush = new PdfSolidBrush(Color.Green);
    layer.Graphics.DrawEllipse(pen, brush, 50, 70, 200, 60);
    
    pdf.SaveToFile("LayerVisibility.pdf", FileFormat.PDF);
            
}
Monday, 18 September 2017 09:28

Add Tab Stops to Word Paragraphs in C#

Tab stops are markers placed on the ruler that define how text or numbers are aligned on a line. To add tab stops to a paragraph in Microsoft Word, we need to open the Tabs dialog box and then set the tab stop position, alignment and leader as shown below.

Add Tab Stops to Word Paragraphs in C#

This article elaborates how to add tab stops to paragraphs in word document programmatically using Spire.Doc.

Detail steps:

Step 1: Instantiate a Document object and add a section to it.

Document document = new Document();
Section section = document.AddSection(); 

Step 2: Add paragraph 1 to the section.

Paragraph paragraph1 = section.AddParagraph();

Step 3: Add tab stops to paragraph 1.

//Add tab and set its position (in points)
Tab tab = paragraph1.Format.Tabs.AddTab(28);
//Set tab alignment
tab.Justification = TabJustification.Left;
//move to next tab and append text
paragraph1.AppendText("\tWashing Machine");

//Add another tab and set its position (in points)
tab = paragraph1.Format.Tabs.AddTab(280);
//Set tab alignment
tab.Justification = TabJustification.Left;
//Specify tab leader type
tab.TabLeader = TabLeader.Dotted;
//move to next tab and append text
paragraph1.AppendText("\t$650"); 

Step 4: Add paragraph 2 to the section.

Paragraph paragraph2 = section.AddParagraph();

Step 5: Add tab stops to paragraph 2.

//Add tab and set its position (in points)
tab = paragraph2.Format.Tabs.AddTab(28);
//Set tab alignment
tab.Justification = TabJustification.Left;
//move to next tab and append text
paragraph2.AppendText("\tRefrigerator");

//Add another tab and set its position (in points)
tab = paragraph2.Format.Tabs.AddTab(280);
//Set tab alignment
tab.Justification = TabJustification.Left;
//Specify tab leader type
tab.TabLeader = TabLeader.NoLeader;
//move to next tab and append text
paragraph2.AppendText("\t$800"); 

Step 6: Save and close the document object.

document.SaveToFile("Tab.docx", FileFormat.Docx2013);
document.Close();

Screenshot:

Add Tab Stops to Word Paragraphs in C#

Full code:

//Instantiate a Document object
Document document = new Document();
//Add a section
Section section = document.AddSection();            

//Add paragraph 1
Paragraph paragraph1 = section.AddParagraph();

//Add tab and set its position (in points)
Tab tab = paragraph1.Format.Tabs.AddTab(28);
//Set tab alignment
tab.Justification = TabJustification.Left;
//move to next tab and append text
paragraph1.AppendText("\tWashing Machine");

//Add another tab and set its position (in points)
tab = paragraph1.Format.Tabs.AddTab(280);
//Set tab alignment
tab.Justification = TabJustification.Left;
//Specify tab leader type
tab.TabLeader = TabLeader.Dotted;
//move to next tab and append text
paragraph1.AppendText("\t$650"); 

//Add paragraph 2
Paragraph paragraph2 = section.AddParagraph();

//Add tab and set its position (in points)
tab = paragraph2.Format.Tabs.AddTab(28);
//Set tab alignment
tab.Justification = TabJustification.Left;
//move to next tab and append text
paragraph2.AppendText("\tRefrigerator"); //move to next tab and append text

//Add another tab and set its position (in points)
tab = paragraph2.Format.Tabs.AddTab(280);
//Set tab alignment
tab.Justification = TabJustification.Left;
//Specify tab leader type
tab.TabLeader = TabLeader.NoLeader;
//move to next tab and append text
paragraph2.AppendText("\t$800"); 

//Save and close the document object            
document.SaveToFile("Tab.docx", FileFormat.Docx2013);
document.Close();
Friday, 15 September 2017 06:43

Generate QR Code in Java

In the previous post, we have demonstrated how to use Spire.Barcode for Java to create barcode images in Java applications. This tutorial provides code sample for generating QR code in Java.

package GenerateBarcode;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import com.spire.barcode.BarCodeGenerator;
import com.spire.barcode.BarCodeType;
import com.spire.barcode.BarcodeSettings;
import com.spire.barcode.QRCodeECL;
import com.sun.javafx.print.Units;

public class QR_Code {

	public static void main(String[] args) throws IOException {

        //create an instance of BarcodeSetteings
        BarcodeSettings settings = new BarcodeSettings();
        //set barcode type
        settings.setType(BarCodeType.QR_CODE);
        //set barcode data
        settings.setData("ABC 123456789");
        //set dispaly text
        settings.setData2D("ABC 123456789");
        //show text on bottom
        settings.setShowTextOnBottom(true);
        //set the border invisible
        settings.hasBorder(false);
        //set width of the barcode module
        settings.setX(2);
        //set the error correction level
        settings.setQRCodeECL(QRCodeECL.M);    
        //create BarCodeGenerator object based on settings
        BarCodeGenerator barCodeGenerator = new BarCodeGenerator(settings);
        //generate image data and store in BufferedImage instance
        BufferedImage bufferedImage = barCodeGenerator.generateImage();
        //save to image
        ImageIO.write(bufferedImage,"png",new File("QR_CODE.png"));
        System.out.println("Complete!");
	}

}

Output:

Generate QR Code in Java

With Spire.XLS for .NET, we could easily add different kinds of charts to Excel worksheet, such as Pie Chart, Column Chart, bar chart, line chart, radar chart, Doughnut chart, pyramid chart, etc. In this article, we'll show you how to remove chart from Excel worksheet by using Spire.XLS.

Below is a sample document which contains a chart and table from the Excel worksheet, then we'll remove the chart from the slide.

How to remove chart from Excel worksheet in C#, VB.NET

C# Code Snippet of how to remove the chart from Excel:

Step 1: Create an instance of Excel workbook and load the document from file.

Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

Step 2: Get the first worksheet from the workbook.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Get the first chart from the first worksheet.

IChartShape chart = sheet.Charts[0];

Step 4: Remove the chart.

chart.Remove();

Step 5: Save the document to file.

workbook.SaveToFile("RemoveChart.xlsx");

Effective screenshot:

How to remove chart from Excel worksheet in C#, VB.NET

Full code:

[C#]
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet sheet = workbook.Worksheets[0];
IChartShape chart = sheet.Charts[0];
chart.Remove();
workbook.SaveToFile("RemoveChart.xlsx");
[VB.NET]
Dim workbook As New Workbook()
workbook.LoadFromFile("Sample.xlsx")
Dim sheet As Worksheet = workbook.Worksheets(0)
Dim chart As IChartShape = sheet.Charts(0)
chart.Remove()
workbook.SaveToFile("RemoveChart.xlsx")

In Word, textbox can contain multiple elements such as text, image and table. This article demonstrates how to insert table into word textbox, and read and delete existing table from word textbox using Spire.Doc.

Insert table

//Create a Document instance
Document document = new Document();

//Add a section
Section section = document.AddSection();
//Add a paragraph to the section
Paragraph paragraph = section.AddParagraph();

//Add textbox to the paragraph
TextBox textbox = paragraph.AppendTextBox(300, 100);

//Add text to textbox
Paragraph textboxParagraph = textbox.Body.AddParagraph();
TextRange textboxRange = textboxParagraph.AppendText("Table 1");
textboxRange.CharacterFormat.FontName = "Arial";

//Insert table to textbox
Table table = textbox.Body.AddTable(true);
//Specify the number of rows and columns of the table
table.ResetCells(4, 4);

string[,] data = new string[,]  
{  
{"Name","Age","Gender","ID" },  
{"John","28","Male","0023" },  
{"Steve","30","Male","0024" },  
{"Lucy","26","female","0025" }  
};

//Add data to table 
for (int i = 0; i < 4; i++)
{
    for (int j = 0; j < 4; j++)
    {
        TextRange tableRange = table[i, j].AddParagraph().AppendText(data[i, j]);
        tableRange.CharacterFormat.FontName = "Arial";
    }
}

//Apply style to table
table.ApplyStyle(DefaultTableStyle.LightGridAccent3);

//Save the document
document.SaveToFile("Output.docx", FileFormat.Docx2013);

Insert, Read and Delete Table from Word Textbox in C#

Read table

//Create a Document instance and load the word document
Document document = new Document("Output.docx");

//Get the first textbox
TextBox textbox = document.TextBoxes[0];

//Get the first table in the textbox
Table table = textbox.Body.Tables[0] as Table;

StringBuilder sb = new StringBuilder();

//Loop through the paragraphs of the table and extract text to a .txt file
foreach (TableRow row in table.Rows)
{
    foreach (TableCell cell in row.Cells)
    {
        foreach (Paragraph paragraph in cell.Paragraphs)
        {
            sb.AppendLine(paragraph.Text);
        }
    }
}
File.WriteAllText("text.txt", sb.ToString());

Insert, Read and Delete Table from Word Textbox in C#

Delete table

//Create a Document instance and load the word document
Document document = new Document("Output.docx");

//Get the first textbox
TextBox textbox = document.TextBoxes[0];

//Remove the first table from the textbox
textbox.Body.Tables.RemoveAt(0);

//Save the document
document.SaveToFile("RemoveTable.docx", FileFormat.Docx2013);

Insert, Read and Delete Table from Word Textbox in C#

When creating charts from scratch in PowerPoint slide, an Excel sheet with some dummy data will automatically be generated. The dummy data can be overwritten with the data from data source as well as from an existing Excel file. This article demonstrates how we can create chart in PowerPoint using the data in Excel file.

This solution requires Spire.Presneation.dll and Spire.Xls.dll to be added as references in project. Please download Spire.Office and reference the corresponding DLLs from it.

Here is the Excel sheet containing our sample data.

How to Create Chart Using Excel Data in PowerPoint in C#, VB.NET

Step 1: Create a Presentation document.

Presentation ppt = new Presentation();

Step 2: Append a column chart in the first slide.

RectangleF rect = new RectangleF(40, 100, 550, 320);
IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.ColumnClustered, rect);

Step 3: Clear the default dummy data.

chart.ChartData.Clear(0, 0, 5, 5);

Step 4: Load an existing Excel file to Workbook instance and get the first worksheet.

Workbook wb = new Workbook();
wb.LoadFromFile("data.xlsx");
Worksheet sheet = wb.Worksheets[0];

Step 5: Import data from the worksheet to chart table.

for (int r = 0; r < sheet.AllocatedRange.RowCount; r++)
{
    for (int c = 0; c < sheet.AllocatedRange.ColumnCount; c++)
    {
        chart.ChartData[r, c].Value = sheet.Range[r + 1, c + 1].Value2;
    }
}

Step 6: Set the series label and categories labels.

chart.Series.SeriesLabel = chart.ChartData["B1", "B1"];
chart.Categories.CategoryLabels = chart.ChartData["A2","A13"];

Step 7: Set the series values.

chart.Series[0].Values = chart.ChartData["B2","B13"];

Step 8: Save the file.

ppt.SaveToFile("chart.pptx",Spire.Presentation.FileFormat.Pptx2013);

Output:

How to Create Chart Using Excel Data in PowerPoint in C#, VB.NET

Full Code:

[C#]
using System;
using Spire.Presentation;
using System.Drawing;
using Spire.Presentation.Charts;
using Spire.Xls;

namespace CreateChartFromExcelData
{
    class Program
    {
        static void Main(string[] args)
        {
            //initialize an instance of Presentation class
            Presentation ppt = new Presentation();
            RectangleF rect = new RectangleF(40, 100, 550, 320);
            IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.ColumnClustered, rect);

            //clear the default dummy data
            chart.ChartData.Clear(0, 0, 5, 5);

            //load an existing Excel file to Workbook object
            Workbook wb = new Workbook();
            wb.LoadFromFile("data.xlsx");
            Worksheet sheet = wb.Worksheets[0];

            //import data from the sheet to chart table
            for (int r = 0; r < sheet.AllocatedRange.RowCount; r++)
            {
                for (int c = 0; c < sheet.AllocatedRange.ColumnCount; c++)
                {
                    chart.ChartData[r, c].Value = sheet.Range[r + 1, c + 1].Value2;
                }
            }

            //add chart title
            chart.ChartTitle.TextProperties.Text = "Monthly Sales Report";
            chart.ChartTitle.TextProperties.IsCentered = true;
            chart.ChartTitle.Height = 30;
            chart.HasTitle = true;

            //set the series label
            chart.Series.SeriesLabel = chart.ChartData["B1", "B1"];

            //set the category labels
            chart.Categories.CategoryLabels = chart.ChartData["A2","A13"];

            //set the series values
            chart.Series[0].Values = chart.ChartData["B2","B13"];

            //save the file
            ppt.SaveToFile("chart.pptx",Spire.Presentation.FileFormat.Pptx2013);
        }
    }
}
[VB.NET]
Imports Spire.Presentation
Imports System.Drawing
Imports Spire.Presentation.Charts
Imports Spire.Xls

Namespace CreateChartFromExcelData
    Class Program
        Private Shared Sub Main(args As String())
			'initialize an instance of Presentation class
			Dim ppt As New Presentation()

            Dim rect As New RectangleF(40, 100, 550, 320)

            Dim chart As IChart = ppt.Slides(0).Shapes.AppendChart(ChartType.ColumnClustered, rect)

			'clear the default dummy data
			chart.ChartData.Clear(0, 0, 5, 5)

			'load an existing Excel file to Workbook object
			Dim wb As New Workbook()

            wb.LoadFromFile("data.xlsx")
			Dim sheet As Worksheet = wb.Worksheets(0)

			'import data from the sheet to chart table
			For r As Integer = 0 To sheet.AllocatedRange.RowCount - 1
				For c As Integer = 0 To sheet.AllocatedRange.ColumnCount - 1

                    chart.ChartData(r, c).Value = sheet.Range(r + 1, c + 1).Value2
                Next

            Next

			'add chart title
			chart.ChartTitle.TextProperties.Text = "Monthly Sales Report"
			chart.ChartTitle.TextProperties.IsCentered = True
            chart.ChartTitle.Height = 30
			chart.HasTitle = True

			'set the series label

            chart.Series.SeriesLabel = chart.ChartData("B1", "B1")

			'set the category labels

            chart.Categories.CategoryLabels = chart.ChartData("A2", "A13")

			'set the series values

            chart.Series(0).Values = chart.ChartData("B2", "B13")

			'save the file
			ppt.SaveToFile("chart.pptx", Spire.Presentation.FileFormat.Pptx2013)
		End Sub

    End Class
End Namespace
Thursday, 07 September 2017 03:17

Remove conditional format from Excel in C#

With the help of Spire.XLS, we can set the conditional format the Excel cell in C# and VB.NET. We can also use Spire.XLS to remove the conditional format from a specific cell or the entire Excel worksheet. This article will demonstrate how to remove conditional format from Excel in C#.

Firstly, view the original Excel worksheet with conditional formats:

Remove conditional format from Excel in C#

Step 1: Create an instance of Excel workbook and load the document from file.

Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

Step 2: Get the first worksheet from the workbook.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Remove the conditional formats from the specific Excel Cell B2.

sheet.Range["B2"].ConditionalFormats.Remove();

Step 4: Remove all the conditional formats from the whole Excel worksheet.

sheet.AllocatedRange.ConditionalFormats.Remove();

Step 5: Save the document to file.

workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010);

Remove the conditional format from a special Excel range B2:

Remove conditional format from Excel in C#

Remove all the conditional formats from the entire Excel worksheet:

Remove conditional format from Excel in C#

Full codes of how to remove the conditional formats from Excel worksheet:

Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

Worksheet sheet = workbook.Worksheets[0];

//sheet.Range["B2"].ConditionalFormats.Remove();

sheet.AllocatedRange.ConditionalFormats.Remove();

workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010);

In Spire.XLS, we can hide or show the headers of rows and columns by setting the RowColumnHeadersVisible property of XlsWorksheet class. This article elaborates the steps of how to accomplish this function using Spire.XLS.

The following screenshot shows the input file which contain one worksheet with row and column headers.

Hide or Show Row Column Headers in Excel with C#

Detail steps:

Step 1: Instantiate a Workbook instance 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 or show the headers of rows and columns in the worksheet.

//Hide the headers of rows and columns
sheet.RowColumnHeadersVisible = false;

//Show the headers of rows and columns
//sheet.RowColumnHeadersVisible = true;

Step 4: Save the file.

workbook.SaveToFile("Output.xlsx");

The screenshot after hiding the row and column headers:

Hide or Show Row Column Headers in Excel with C#

Full code:

// Instantiate a Workbook instance
Workbook workbook = new Workbook();
//Load the Excel file
workbook.LoadFromFile("Input.xlsx");

//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];

//Hide the headers of rows and columns
sheet.RowColumnHeadersVisible = false;

//Show the headers of rows and columns
//sheet.RowColumnHeadersVisible = true;
            
//Save the file
workbook.SaveToFile("Output.xlsx");