Showing posts with label Excel. Show all posts
Showing posts with label Excel. Show all posts

Monday, December 8, 2008

Programmatically set border width of Excel cell

This MSDN article briefly explains how to do this: http://msdn.microsoft.com/en-us/library/bb209714.aspx

and here is an example that I am using in my code. It just sets the left border weight to thick for the cell located at 1,2. 

range = (Microsoft.Office.Interop.Excel.Range)wsheet.Cells[1, 2];
                                range.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeLeft].Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick;

Wednesday, July 23, 2008

Programmatically remove digital signatures from Excel document

Here is some sample code to remove all digital signatures from an Excel workbook. This can be run from a Windows app or Console app. I'm going to try to make it work within a SharePoint document library event handler. That should be interesting. Basically the idea is to have a document library that has a bunch of documents that are digitally signed and then every month get reset by removing all the digital signatures. Hope this runs in the event handler.

Microsoft.Office.Interop.Excel.Application eApp = null; Microsoft.Office.Interop.Excel.Workbook wb = null;

//gets our workbook
eApp = new Microsoft.Office.Interop.Excel.Application();
wb = eApp.Workbooks.Open(textBox1.Text, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

//makes it visible and activates the workbook

//eApp.Visible = true;
//wb.Activate();

//get signatures

Microsoft.Office.Core.SignatureSet sigs = wb.Signatures;

//remove all the signatures

foreach (Microsoft.Office.Core.Signature sig in sigs)
{ sig.Delete(); }

//save and close the form

wb.Save();
wb.Close(Type.Missing, Type.Missing, Type.Missing);
wb = null;
eApp = null;