Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
DBF (DataBase File) is a legacy database file format originally introduced by dBASE in the early 1980s. Despite the age of the format, DBF files are still widely used in many industries for storing structured data, particularly in accounting, GIS, and other specialized applications. Aspose.Cells allows you to integrate these legacy files into modern Aspose.Cells for Node.js via C++ spreadsheet workflows seamlessly.
The library supports both reading and writing DBF files, giving you the ability to:
DBF files can also be opened directly in Microsoft Excel and other spreadsheet applications, making them a convenient bridge between legacy systems and modern spreadsheet tools.
Aspose.Cells supports the following DBF format versions:
The library provides comprehensive support for the following operations:
When working with DBF files, keep the following constraints in mind:
YYYYMMDD format.Aspose.Cells makes it straightforward to load data from a DBF file into a Workbook object. The library uses the LoadOptions class to specify the source format, ensuring that the data is interpreted correctly during the loading process.
To read a DBF file, you need to create a LoadOptions instance, set its LoadFormat property to LoadFormat.Dbf, and pass it to the Workbook constructor along with the file path. Once loaded, the data becomes accessible through the Worksheets collection, where you can iterate through cells, extract values, or manipulate the data as needed.
The following example demonstrates how to load an existing DBF file into Aspose.Cells, access its first worksheet, and read the cell values.
const AsposeCells = require("aspose.cells");
const path = require("path");
const dataDir = "Data/";
const filePath = path.join(dataDir, "example.dbf");
const loadOptions = new AsposeCells.LoadOptions(AsposeCells.LoadFormat.Dbf);
const workbook = new AsposeCells.Workbook(filePath, loadOptions);
const worksheet = workbook.getWorksheets().get(0);
const cells = worksheet.getCells();
const sb = [];
const maxRow = cells.getMaxDataRow();
const maxCol = cells.getMaxDataColumn();
for (let i = 0; i <= maxRow; i++)
{
for (let j = 0; j <= maxCol; j++)
{
const cell = cells.get(i, j);
const value = cell.getStringValue();
sb.push("|");
sb.push(value);
}
sb.push("|");
sb.push("\n");
}
console.log(sb.join(""));
const outputPath = path.join(dataDir, "output.xlsx");
workbook.save(outputPath, AsposeCells.SaveFormat.Xlsx);
console.log("DBF file loaded successfully. Converted XLSX saved at: " + outputPath);
Writing data to a DBF file follows a similar pattern to saving any other spreadsheet format with Aspose.Cells. You create or load a Workbook, populate the worksheet with data, and then call the Save method while specifying SaveFormat.Dbf as the target format.
To create a DBF file, follow these steps:
Workbook instance.Worksheets collection.Workbook.Save method, passing the file path and SaveFormat.Dbf as parameters.The following example demonstrates how to create a new DBF file from scratch. It populates a worksheet with sample data containing different data types (strings, numbers, and dates) to illustrate how field types are handled when exporting to the DBF format.
const AsposeCells = require("aspose.cells");
const path = require("path");
const fs = require("fs");
const outputDir = "C:\\Output\\";
const filePath = path.join(outputDir, "output.dbf");
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const workbook = new AsposeCells.Workbook();
const worksheet = workbook.getWorksheets().get(0);
const cells = worksheet.getCells();
// Column headers
cells.get(0, 0).putValue("ID");
cells.get(0, 1).putValue("Name");
cells.get(0, 2).putValue("Department");
cells.get(0, 3).putValue("Salary");
cells.get(0, 4).putValue("HireDate");
// Data row 1
cells.get(1, 0).putValue(101);
cells.get(1, 1).putValue("John Smith");
cells.get(1, 2).putValue("Engineering");
cells.get(1, 3).putValue(75000.50);
cells.get(1, 4).putValue(new Date(2020, 2, 15));
// Data row 2
cells.get(2, 0).putValue(102);
cells.get(2, 1).putValue("Jane Doe");
cells.get(2, 2).putValue("Marketing");
cells.get(2, 3).putValue(68000.75);
cells.get(2, 4).putValue(new Date(2019, 6, 22));
// Data row 3
cells.get(3, 0).putValue(103);
cells.get(3, 1).putValue("Bob Johnson");
cells.get(3, 2).putValue("Finance");
cells.get(3, 3).putValue(82000.00);
cells.get(3, 4).putValue(new Date(2021, 0, 10));
// Data row 4
cells.get(4, 0).putValue(104);
cells.get(4, 1).putValue("Alice Brown");
cells.get(4, 2).putValue("Human Resources");
cells.get(4, 3).putValue(71000.25);
cells.get(4, 4).putValue(new Date(2018, 10, 5));
// Data row 5
cells.get(5, 0).putValue(105);
cells.get(5, 1).putValue("Charlie Wilson");
cells.get(5, 2).putValue("Operations");
cells.get(5, 3).putValue(79500.80);
cells.get(5, 4).putValue(new Date(2022, 4, 30));
// Set column widths for better readability
worksheet.getCells().setColumnWidth(0, 8);
worksheet.getCells().setColumnWidth(1, 20);
worksheet.getCells().setColumnWidth(2, 20);
worksheet.getCells().setColumnWidth(3, 12);
worksheet.getCells().setColumnWidth(4, 14);
workbook.save(filePath, AsposeCells.SaveFormat.Dbf);
When transferring data between Aspose.Cells and the DBF format, understanding how data types map between the two systems is important for ensuring data integrity.
Aspose.Cells cell values are automatically converted to the appropriate DBF field types when saving:
YYYYMMDD format.DBF files may use different character encodings depending on the application that created them. Aspose.Cells handles encoding transparently in most cases, but if you encounter character display issues, you may need to verify the encoding of the source file.
DBF field names must adhere to the following rules:
After writing a DBF file, you can verify the result by opening it in Microsoft Excel or any dBASE-compatible application. The data should appear in a tabular layout with the field names as column headers, and the records populated according to the data you provided.
One of the most practical use cases for reading and writing DBF files with Aspose.Cells is converting data between the DBF format and modern spreadsheet formats such as XLSX, XLS, or CSV. Since Aspose.Cells supports a wide range of formats, you can easily load a DBF file and re-save it in any other supported format, or vice versa.
For example, you can read a DBF file, apply formatting or calculations using the Aspose.Cells API, and then save the result as an XLSX file for distribution to users who work with modern spreadsheet applications. Conversely, you can take data from an XLSX or CSV file and export it to DBF format for integration with legacy systems.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.