Summary: Analyze a Nopi manual that can help us make better use of Nopi to operate office
Some customers export or import, the format of Excel is very high, you need to use the Nopi. Code Sample:
ImportsSystemImportssystem.webImportsSystem.Web.UIImportsSystem.Web.UI.WebControlsImportsSystem.IOImportsNpoi. HSSF. UsermodelImportsNpoi. HPSFImportsNpoi. Poifs. FileSystemImportsNpoi. Ss. UsermodelPartial Public Class_defaultInheritsSystem.Web.UI.PageProtected SubPage_Load (ByValSender as Object,ByValE asEventArgs)End Sub 'output file data stream after clicking the button Protected SubButton1_Click (ByValSender as Object,ByValE asEventArgs)DimFileName as String="Test.xls"Response.ContentType="Application/vnd.ms-excel"Response.AddHeader ("content-disposition",String. Format ("attachment;filename={0}", filename)) Response.Clear ()'Call Initialize Excel fileInitializeworkbook ()'Generate DataGeneratedata ()'output Excel file streamResponse.BinaryWrite (WriteToStream (). GetBuffer ()) Response. [End]() End Sub 'Define Workbook PrivateHssfworkbook asHssfworkbook' Private FunctionWriteToStream () asMemoryStream'Write The stream data of workbook to the root directory DimFile as NewMemoryStream () Hssfworkbook. Write (file)ReturnfileEnd Function 'Generate Data Private SubGeneratedata ()'Generate a sheet DimSheet1 asIsheet = Hssfworkbook. Createsheet ("Sheet1") 'Loop adds data to sheetSheet1. CreateRow (0). Createcell (0). Setcellvalue ("This is a Sample") DimX as Integer=1 forI as Integer=1 to the DimRow asIRow =Sheet1. CreateRow (i) forJ as Integer=0 to -row. Createcell (j). Setcellvalue (System.Math.Max (System.Threading.Interlocked.Increment (x), x-1)) Next Next End Sub 'Initialize a workbook (active worksheet) Private SubInitializeworkbook () Hssfworkbook=NewHssfworkbook ()" "/create A entry of documentsummaryinformation DimDsi asDocumentsummaryinformation =propertysetfactory.createdocumentsummaryinformation () Dsi.company="Npoi Team"Hssfworkbook. Documentsummaryinformation=DSi" "/create A entry of SummaryInformation DimSi asSummaryInformation =propertysetfactory.createsummaryinformation () si. Subject="Npoi SDK Example"Hssfworkbook. SummaryInformation=siEnd SubEnd Class
Http://files.cnblogs.com/files/KingUp/npoi%E5%AE%9E%E4%BE%8B.rar
Nopi User Manual