c# - ".TextToColumns" with ".NumberFormat" -
i've got text file i'm trying save xlsx file. before saving , closing need perform texttocolumns , need column "h" remain in "text" format.
the below code converts column "h" "text" format when ".texttocolumns" executes column "h" changes "custom" format changing the data.
microsoft.office.interop.excel.application oxl; microsoft.office.interop.excel.workbook datab; microsoft.office.interop.excel.worksheet datas; string path = @"c:\users\fakename\desktop\extracted_formatted samplefile.csv"; oxl = new microsoft.office.interop.excel.application(); datab = oxl.workbooks.open(path, 0, false, 5, missing.value, missing.value, false, missing.value, missing.value, false, false, missing.value, false, false, false); datab.application.displayalerts = false; oxl.visible = true; datas = (microsoft.office.interop.excel.worksheet)datab.activesheet; range excelrange = datas.get_range("h1").entirecolumn; excelrange.numberformat = "@"; datas.get_range("a1", ("a" + datas.usedrange.rows.count)).texttocolumns( type.missing, microsoft.office.interop.excel.xltextparsingtype.xldelimited, microsoft.office.interop.excel.xltextqualifier.xltextqualifiernone, false, false, false, false, false, true, "|", type.missing, type.missing, type.missing, type.missing); datas.name = "psh"; datas.saveas(@"c:\users\fakename\desktop\2\moresamplefiles", microsoft.office.interop.excel.xlfileformat.xlworkbookdefault); datab.close(missing.value, missing.value, missing.value); oxl.quit();
Comments
Post a Comment