excel - How to preserve a formula's reference to a worksheet when the worksheet is deleted and replaced using C#? -
how keep formulas working after replacing sheet? mean how preserve formula's reference worksheet when worksheet deleted , replaced? in c#
using excel = microsoft.office.interop.excel; excel.application excelapp = new excel.applicationclass(); excel.workbook excelworkbook = excelapp.workbooks.open(connection.datasource, 0, false, 5, "", "", false, excel.xlplatform.xlwindows, "", true, false, 0, true, false, false); foreach (excel.worksheet sh in excelworkbook.sheets) { if (sh.name == sheetname || sh.name == "_"+sheetname) { sh.application.displayalerts = false; sh.delete(); } } excelworkbook.save(); excelworkbook.close(true, excelworkbook.fullname, null); excelapp.quit();
later i'm invoking sql command "create table" same name. formulas not working
what have is, in sheet contains formulas, firstly convert them away formulas (this stop excel creating errors in formulas when delete sheet thse formulas referencing).
so, example, find/replace , replace "=" with, example "#" (or other character or set of characters you're sure you're not using in sheet). thsi stop formula creating errored reference.
then delete sheet, add in new sheet
then re-replace values in formula sheet "#" "=".
so long new sheet has same name old sheet, should go.
hope helps.
Comments
Post a Comment