Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
70
Excel Workbook.Load CellFormat bug?
posted
Workbook workbook = Workbook.Load("GenericReport.xls");
Worksheet currentSheet = workbook.Worksheets[0];

And then I do

 someCell.CellFormat.Font.Color = Color.White;
someCell.CellFormat.FillPatternBackgroundColor = Color.Black;

and then

workbook.Save(location);

I load the workbook because I have a macro in there. But then the style doesn't get applied. If I just do:

Workbook workbook = new Workbook();
workbook.Worksheets.Add("blah");
Worksheet currentSheet = Workbook.Worksheets[0];

then the style gets applied. Tips? ;)

Parents
  • 70
    posted

    This is a full example anybody should be able to run:

    using System.Drawing;
    using Infragistics.Excel;
    
    namespace ConsoleApplication1
    {
    	internal class Program
    	{
    		private static void Main(string[] args)
    		{
    			Workbook workbook = new Workbook();
    			workbook.Worksheets.Add("fap");
    			Worksheet worksheet = workbook.Worksheets[0];
    
    
    			worksheet.Rows[0].Cells[0].Value = "hi";
    			worksheet.Rows[0].Cells[0].CellFormat.FillPatternBackgroundColor = Color.Black;
    			worksheet.Rows[0].Cells[0].CellFormat.Font.Color = Color.White;
    
    
    			workbook.Save(@"c:\test.xls");
    
    			workbook = null;
    
    			Workbook workbook2 = Workbook.Load(@"c:\test.xls");
    			Worksheet worksheet2 = workbook2.Worksheets[0];
    
    
    			worksheet2.Rows[1].Cells[0].Value = "hi";
    			worksheet2.Rows[1].Cells[0].CellFormat.FillPatternBackgroundColor = Color.Black;
    			worksheet2.Rows[1].Cells[0].CellFormat.Font.Color = Color.White;
    
    			workbook2.Save(@"c:\fap2.xls");
    		}
    	}
    }
Reply Children