Knowledgebase (2311)
Children categories
Excel and CSV (Comma-Separated Values) are two commonly used file formats for managing and storing tabular data in various industries. Excel organizes data in rows and columns and provides users with a wide range of advanced features for data manipulation, analysis and visualization, whereas CSV stores data in a plain text format that is lightweight and highly compatible with various applications. Converting Excel files to CSV format can be very helpful when users need to exchange or import Excel data in different programs. Conversely, users who require more advanced data analysis features, such as creating charts or applying formulas, may find it beneficial to convert CSV files to Excel format. In this article, we will demonstrate how to convert Excel to CSV or CSV to Excel in C++ using Spire.XLS for C++.
Install Spire.XLS for C++
There are two ways to integrate Spire.XLS for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.
Integrate Spire.XLS for C++ in a C++ Application
Convert Excel to CSV in C++
Spire.XLS for C++ offers the XlsWorksheet->SaveToFile (LPCWSTR_S fileName, LPCWSTR_S separator, Spire::Common::Encoding* encoding) method to convert a worksheet in an Excel file to CSV. The detailed steps are as follows:
- Initialize an instance of the Workbook class.
- Load an Excel file using Workbook->LoadFromFile() method.
- Get a specific worksheet in the workbook by its index using Workbook->GetWorksheets()->Get(int index) method.
- Save the worksheet to a CSV file using XlsWorksheet->SaveToFile (LPCWSTR_S fileName, LPCWSTR_S separator, Spire::Common::Encoding* encoding) method.
- C++
#include "Spire.Xls.o.h";
using namespace Spire::Xls;
int main()
{
//Initialize an instance of the Workbook class
Workbook* workbook = new Workbook();
//Load an Excel file
workbook->LoadFromFile(L"Input.xlsx");
//Get the first worksheet
Worksheet* sheet = workbook->GetWorksheets()->Get(0);
//Save the worksheet to a CSV file
sheet->SaveToFile(L"ExcelToCsv.csv", L",", Encoding::GetUTF8());
workbook->Dispose();
delete workbook;
}

Convert Visible Data in Excel to CSV in C++
When converting an Excel worksheet to CSV using the above code, all data, including both visible and hidden data, will be saved to CSV. If you only want to save visible data in the worksheet to CSV, you can use the XlsWorksheet->SaveToFile (LPCWSTR_S fileName, LPCWSTR_S separator, bool retainHiddenData) method. The detailed steps are as follows:
- Initialize an instance of the Workbook class.
- Load an Excel file using Workbook->LoadFromFile() method.
- Get a specific worksheet in the workbook by its index using Workbook->GetWorksheets()->Get(int index) method.
- Save visible data in the worksheet to a CSV file using XlsWorksheet->SaveToFile (LPCWSTR_S fileName, LPCWSTR_S separator, bool retainHiddenData) method.
- C++
#include "Spire.Xls.o.h";
using namespace Spire::Xls;
int main()
{
//Initialize an instance of the Workbook class
Workbook* workbook = new Workbook();
//Load an Excel file
workbook->LoadFromFile(L"Input.xlsx");
//Get the first worksheet
Worksheet* sheet = workbook->GetWorksheets()->Get(0);
//Save visible data in the worksheet to a CSV file
sheet->SaveToFile(L"ExcelToCsv1.csv", L",", false);
workbook->Dispose();
delete workbook;
}

Convert CSV to Excel in C++
To convert a CSV file to Excel, you need to load the CSV file using Workbook->LoadFromFile(LPCWSTR_S fileName, LPCWSTR_S separator) method, then use the Workbook->SaveToFile (LPCWSTR_S fileName, ExcelVersion version) method to save it to an Excel file. The detailed steps are as follows:
- Initialize an instance of the Workbook class.
- Load a CSV file with separator using Workbook->LoadFromFile(LPCWSTR_S fileName,LPCWSTR_S separator) method.
- Get a specific worksheet in the file by its index using Workbook->GetWorksheets()->Get(int index) method.
- Set ignore error option to ignore errors when saving numbers in a specific cell range as text using Worksheet->GetRange(LPCWSTR_S name)->SetIgnoreErrorOptions(IgnoreErrorType::NumberAsText) method.
- Auto-fit column widths using Worksheet->GetAllocatedRange()->AutoFitColumns() method.
- Save the CSV file to an Excel file using Workbook->SaveToFile (LPCWSTR_S fileName, ExcelVersion version) method.
- C++
#include "Spire.Xls.o.h";
using namespace Spire::Xls;
int main()
{
//Initialize an instance of the Workbook class
Workbook* workbook = new Workbook();
//Load a CSV file with separator
workbook->LoadFromFile(L"ExcelToCSV.csv", L",");
//Get the first worksheet
Worksheet* sheet = workbook->GetWorksheets()->Get(0);
//Set ignore error option to ignore errors when saving numbers in a specific cell range as text
sheet->GetRange(L"C2:C11")->SetIgnoreErrorOptions(IgnoreErrorType::NumberAsText);
//Auto-fit column widths
sheet->GetAllocatedRange()->AutoFitColumns();
//Save the file to an Excel XLSX file
workbook->SaveToFile(L"CsvToExcel.xlsx", ExcelVersion::Version2013);
workbook->Dispose();
delete workbook;
}

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.
In Word, a watermark is a semi-transparent text or image that you can place in the background. Typically, watermarks are used to emphasize something important about a document. For example, you can use it to remind the user that the content is confidential or a draft. Or other times, you may want to add a washout mark to include the company logo in the document. In this article, you will learn how to insert text or image watermarks to Word documents in C++ using Spire.Doc for C++.
Install Spire.Doc for C++
There are two ways to integrate Spire.Doc for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.
Integrate Spire.Doc for C++ in a C++ Application
Insert a Text Watermark to Word in C++
Spire.Doc for C++ offers the TextWatermark class to represent a text watermark. The content and appearance of the watermark can be set using the methods under it. Once a text watermark is created, you can apply it to the whole document by using Document->SetWatermark() method. The following are the detailed steps.
- Create a Document object.
- Load a Word file using Document->LoadFromFile() method.
- Create a TextWatermark object.
- Se the content and appearance of the watermark using the methods under the TextWatermark object.
- Apply the text watermark to the document using Document->SetWatermrak() method.
- Save the document using Document->SaveToFile() method.
- C++
#include "Spire.Doc.o.h";
using namespace Spire::Doc;
using namespace std;
int main() {
//Create a Document object
intrusive_ptr<Document> document = new Document();
//Load a Word file
document->LoadFromFile(L"C:\\Users\\Administrator\\Desktop\\sample.docx");
//Create a TextWatermark object
intrusive_ptr<TextWatermark> txtWatermark = new TextWatermark();
//Set the content and format of the text watermark
txtWatermark->SetText(L"CONFIDENTIAL");
txtWatermark->SetFontSize(40);
txtWatermark->SetSemitransparent(90);
txtWatermark->SetFontName(L"Arial Black");
txtWatermark->SetColor(Color::GetBlue());
txtWatermark->SetLayout(WatermarkLayout::Diagonal);
//Apply the text watermark to the document
document->SetWatermark(txtWatermark);
//Save the document
document->SaveToFile(L"Output/TextWatermark.docx", FileFormat::Docx2013);
document->Close();
}

Insert an Image Watermark to Word in C++
Likewise, an image watermark can be created using PictureWatermark class. Once created, you can apply it to a Word document using Document->SetWatermark() method. Here are the detailed steps.
- Create a Document object.
- Load a Word file using Document->LoadFromFile() method.
- Create a PictureWatermark object.
- Set the image and appearance of the watermark using the methods under the PictureWatermark object.
- Apply the image watermark to the document using Document->SetWatermrak() method.
- Save the document using Document->SaveToFile() method.
- C++
#include "Spire.Doc.o.h";
using namespace Spire::Doc;
using namespace std;
int main() {
//Create a Document object
intrusive_ptr<Document> document = new Document();
//Load a Word file
document->LoadFromFile(L"C:\\Users\\Administrator\\Desktop\\sample.docx");
//Create a PictureWatermark object
intrusive_ptr<PictureWatermark> pictureWatermark = new PictureWatermark();
//Specify image for the watermark
pictureWatermark->SetPicture(L"C:\\Users\\Administrator\\Desktop\\company-png.png");
pictureWatermark->SetScaling(100);
pictureWatermark->SetIsWashout(false);
//Apply the image watermark to the document
document->SetWatermark(pictureWatermark);
//Save the document
document->SaveToFile(L"Output/ImageWatermark.docx", FileFormat::Docx2013);
document->Close();
}

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.
PDF is a popular and widely used file format, but when it comes to giving presentations to others in meetings, classes or other scenarios, PowerPoint is always preferred over PDF files because it contains rich presentation effects that can better capture the attention of your audience. In this article, you will learn how to convert an existing PDF file to a PowerPoint presentation using Spire.PDF for Java.
Install Spire.PDF for Java
First of all, you're required to add the Spire.Pdf.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.pdf</artifactId>
<version>11.12.16</version>
</dependency>
</dependencies>
Convert PDF to PowerPoint Presentation in Java
From Version 9.2.1, Spire.PDF for Java supports converting PDF to PPTX using PdfDocument.saveToFile() method. With this method, each page of your PDF file will be converted to a single slide in PowerPoint. Below are the steps to convert a PDF file to an editable PowerPoint document.
- Create a PdfDocument instance.
- Load a sample PDF document using PdfDocument.loadFromFile() method.
- Save the document as a PowerPoint document using PdfDocument.saveToFile(String filename, FileFormat.PPTX) method.
- Java
import com.spire.pdf.FileFormat;
import com.spire.pdf.PdfDocument;
public class PDFtoPowerPoint {
public static void main(String[] args) {
//Create a PdfDocument instance
PdfDocument pdfDocument = new PdfDocument();
//Load a sample PDF document
pdfDocument.loadFromFile("sample.pdf");
//Convert PDF to PPTX document
pdfDocument.saveToFile("PDFtoPowerPoint.pptx", FileFormat.PPTX);
}
}

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.