Hi Community,
I am currently working on the XLS2DOC converter example and I am wondering how to convert conditionally formatted cells from Excel to Word. Can you please provide a simple example how to get the Word cells of the table formatted the same way as those are displayed (conditionally formatted) in Excel?
Thanks for your support!
Hi Hristo,
Thanks for your posting and using Aspose.Cells for .NET.
There is no direct way to convert your Excel documents into Word documents. You can take images of your worksheet and add them in your word document using Aspose.Words.
Please see the following document how to convert your worksheet into image.
http://www.aspose.com/docs/display/cellsnet/Converting+Worksheet+to+Image
Also there is another approach, you can convert your Excel documents into PDF using Aspose.Cells and then convert the output PDF into Word document using Aspose.Pdf. Please see the following documentation articles for your reference.
http://www.aspose.com/docs/display/cellsnet/Converting+Excel+to+PDF+Files
Convert PDF to Microsoft Word Documents in .NET|Aspose.PDF for .NET
Using newer versions of Aspose.Cells, you can conveniently and directly convert an Excel file (having all the formatting (conditional, normal, etc.)) to a Word document (DOCX), without requiring any additional steps or using other APIs. The Workbook.Save method can be used for the task while you may also specify the SaveFormat.Docx enumeration.
- For .NET, more details are available on C# EXCEL to WORD - EXCEL to WORD Converter | products.aspose.com page.
- For Java, see the details on Java EXCEL to WORD - EXCEL to WORD Converter | products.aspose.com page.
Sample Code
The process involves loading the Excel file into a Workbook object and then calling the Save method.
C# (.NET)
using Aspose.Cells;
using System;
class Program
{
static void Main(string[] args)
{
try
{
// Load the source Excel file
Workbook workbook = new Workbook("input.xlsx"); // Replace with your input file path
// Save the workbook as a DOCX file
workbook.Save("output.docx", SaveFormat.Docx); // Specify the output file path and format
Console.WriteLine("Excel file successfully converted to DOCX.");
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}
This example is detailed in the Aspose knowledge base. Also, see the document: Convert Excel to PDF, Image and other formats|Documentation
Java
import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook;
public class ExcelToDocxConverter {
public static void main(String[] args) throws Exception {
// Load the source Excel file
Workbook workbook = new Workbook("input.xlsx"); // Replace with your input file path
// Save the workbook as a DOCX file
workbook.save("output.docx", SaveFormat.DOCX); // Specify the output file path and format
System.out.println("Excel file successfully converted to DOCX.");
}
}
Further details and options can be found in the Aspose documentation.
We recommend you to download the latest version of Aspose.Cells here:
Please feel free to write us back if you have questions or comments.