I have been working on a Windows application in C#. My Requirement is to print a predefined Excel Template with database values for a given Order Number. Means, i have to retrieve data from database(SQL Server) and replacing predefined cell values(Text) (in excel template) with database value. For Example -
In Excel-cell value "SENDER_NAME" will be replaced by "FEDEX", "OrderNo" will be replaced by "1212" and so on. I am using following code to do that.
object missingValue = Type.Missing;
xlWorkBook = xlApp.Workbooks.Open(path, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Cells.Replace("SENDER_NAME", "FEDEX", missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
My PROBLEM is - When some values are not present in database for a given cell text in excel , its replaced by NULL(or blank value), so it lefts spaces while printing. I have to cut down those emptyspaces??
Any solution? Thanks