Support FAQs

How to add an Image into Excel?
A : Please call the method Add to add an image into a worksheet of Excel file. Full code:
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
//insert the picture day.jpg into the sheet and place it in the cell "B3"
sheet.Pictures.Add(3, 2, "day.jpg");
workbook.SaveToFile("result.xlsx");
How to Insert a new Row into a worksheet of a Excel file?
A : Please call the method InsertRow to add a new row into a worksheet of Excel fils. Full code:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet sheet = workbook.Worksheets[0];
//add a new row in the third row
sheet.InsertRow(3);
workbook.SaveToFile("result.xlsx");
How to set print area in XLS?
A : You can set the PrintArea property of the worksheet to do so. Full code:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet sheet = workbook.Worksheets[0];
//set print area from cell "B2" to cell "F8"
sheet.PageSetup.PrintArea = "B2:F8";
workbook.SaveToFile("result.xlsx");
How to Copy Cells with formatting?
A : Spire.XLS provides you a method called Copy to copy cells with formatting. Full code:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet sheet1 = workbook.Worksheets[0];
Worksheet sheet3 = workbook.Worksheets[2];
//copy cell "B2" in sheet1 to cell "C6" in sheet3
sheet1.Range[3, 2].Copy(sheet3.Range[6,3]);
workbook.SaveToFile("result.xlsx");
How to Convert XLS to PDF?
A : First you need to add reference Spire.Pdf and Spire.Common to your project. Then creat an instance of PdfDocument and a PDF converter object . At last, call the method Convert to convert XLS to PDF. Full code:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
PdfConverter pdfConverter = new PdfConverter(workbook);
PdfDocument pdfDocument = new PdfDocument();
//settings of result PDF docement
pdfDocument.PageSettings.Orientation = PdfPageOrientation.Landscape;
pdfDocument.PageSettings.Width = 970;
pdfDocument.PageSettings.Height = 850;
PdfConverterSettings settings = new PdfConverterSettings();
settings.TemplateDocument = pdfDocument;
//convert XLS to PDF using PdfConverter
pdfDocument = pdfConverter.Convert(settings);
pdfDocument.SaveToFile("result.pdf");
How to merge cells in XLS?
A : Spire.XLS provides you a method called Merge to merge cells in XLS. Full code:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet sheet = workbook.Worksheets[0];
//merges cells "B3" "B4"
sheet.Range["B3:B4"].Merge();
workbook.SaveToFile("result.xlsx");
How to rearrange the worksheets in XLS file?
A : Spire.XLS provides you a method called MoveWorksheet to rearrange the worksheets in XLS file? Full code:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet sheet = workbook.Worksheets[3];
//move the fourth worksheet sheet to the first position of the worksheets
sheet.MoveWorksheet(0);
workbook.SaveToFile("result.xlsx");
How to delete columns in excel worksheet?
A : Spire.XLS provides you a method called DeleteColumn to delete columns. This method affect the order of the collection of worksheet immediately. Full code:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet sheet = workbook.Worksheets[1];
//delete the second column
sheet.DeleteColumn(2);
//delete the fourth column
sheet.DeleteColumn(3);
workbook.SaveToFile("result.xlsx");
How to set number format in specified range in XLS?
A : You can use the property NumberFormat of the destination cell to format the NumberValue of cellrange. Full code:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet sheet = workbook.Worksheets[0];
//set number format in specified range
sheet.Range[2, 2, 6, 6].NumberFormat = "$#,##0.00";
sheet.Range["C3"].NumberValue = 3240.689;
sheet.Range["D4"].NumberValue = 5230.123;
workbook.SaveToFile("result.xlsx");
How to add a formula to a cell?
A : Just set the Formula property of the cell to add a formula. Full code:
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//add formula =IF(H7>0,(IF(F7 > 0,(H7-F7)/F7,"""")),"""") to cell "J7"
string formula = @"=IF(H7>0,(IF(F7 > 0,(H7-F7)/F7,"""")),"""")";
worksheet.Range["J7"].Formula = formula;
worksheet.Range["F7"].NumberValue = 5;
worksheet.Range["H7"].NumberValue = 4;
workbook.SaveToFile("result.xlsx", ExcelVersion.Version2007);
How to merge multiple workbooks?
A : Spire.XLS provides you a method called AddCopy to merge Excel files. Full code:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample1.xlsx");
Workbook workbookDest = new Workbook();
workbookDest.LoadFromFile("sample2.xlsx");
//merge workbook with workbookDest
workbookDest.Worksheets.AddCopy(workbook.Worksheets);
workbookDest.SaveToFile("result.xlsx");