

Private HSSFWorkbook CreateExcelWorkbook(IEnumerable inputData)įileStream fs = new FileStream(Server.MapPath(ExcelTemplateFile), FileMode.Open, FileAccess.Read)

Assuming you have split your input into a List of strings const string ExcelTemplateFile = "~/Resources/ExcelInputTemplate.xls" Ĭonst string ExcelWorksheetName = "Output Worksheet"

The sample code snippet looks something like this. Then you just use npoi to make a copy of the template file and manipulate it at a sheet/row/column level and put whatever data you want. Store a “template” excel file you would like in a known location, with the any column headers/formatting that you need. Download it from Codeplex, add reference to the NPOI dlls to your project. Cause: No file found') ") Ĭurrently I am having some file saving errorsįor generating and manipulating excel files, I personally prefer the NPOI library. TextFile.SaveAs (strExcelOutputFilename) Įlse Response.Write("alert('Failed to import. string strExcelOutputFilename = "C:/Documents and Settings/rhlim/My Documents/" + ("yyyyMMddHHmmss")+xlExtension String fileContent = inputReader.ReadToEnd() įileContent = fileContent.Replace('|', ' ') StreamReader inputReader = new StreamReader(TextFile.FileContent) Using (StreamWriter outputWriter = new StreamWriter(File.Create(strExcelOutputFilename))) string strUploadFileName = "C:/Documents and Settings/rhlim/My Documents/Visual Studio 2005/WebSites/SoD/UploadFiles/" + ("yyyyMMddHHmmss") + strExtension Generate the file name to save the text file. If (strExtension != ".TXT" & strExtension!=".txt") String strExtension = Path.GetExtension(strFileName) String strFileName = Server.HtmlEncode(TextFile.FileName) Get the name of the Excel spreadsheet. that the FileUpload control contains a file. Before attempting to import the file, verify String strExcelOutputFilename = "C:/Documents and Settings/rhlim/My Documents/" + ("yyyyMMddHHmmss") + xlExtension Protected void SaveAsExcelBtn_Click(object sender, EventArgs e) Protected void Page_Load(object sender, EventArgs e)

Below is my code: public partial class TextToExcel : .Page I am using VS2005 C# and im trying to convert a pipe delimited text file to excel workbook format.
