StyleExcelUsingOpenXml

所属分类:C#编程
开发工具:C#
文件大小:47KB
下载次数:7
上传日期:2011-05-23 10:25:34
上 传 者orichisonic
说明:  使用OpenXml SDK建立excel,格式化单元格为粗体和使用AxSpreedSheet呈现内容,以及显示每个cell format的属性
(This sample demonstrates how to create a SpreadsheetWorkbook,make cell content bold, show Excel content on the AxSpreedsheet control and show cell format detail on Textbox control. This sample shows how to apply style to Excel2010 via OpenXML SDK. It also uses a lot of features about SpreadsheetML objects such as those included in the OpenXML SDK.Now I will introduce the architecture of Office XML Formats.)

文件列表:
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml.sln (914, 2011-05-18)
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml (0, 2011-05-20)
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml\App.Config (1547, 2011-05-09)
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml\common (0, 2011-05-16)
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml\common\OpenXmlMethod.cs (17365, 2011-05-18)
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml.csproj (7136, 2011-05-18)
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml\Program.cs (531, 2011-05-09)
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml\Properties (0, 2011-05-16)
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml\Properties\AssemblyInfo.cs (1480, 2011-05-09)
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml\Properties\Resources.Designer.cs (2872, 2011-05-09)
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml\Properties\Resources.resx (5612, 2011-05-09)
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml\Properties\Settings.Designer.cs (1741, 2011-05-09)
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml\Properties\Settings.settings (1050, 2011-05-09)
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml\StyleExcelUsingOpenXml.cs (6435, 2011-05-18)
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml\StyleExcelUsingOpenXml.Designer.cs (9004, 2011-05-18)
StyleExcelUsingOpenXml\CSStyleExcelUsingOpenXml\StyleExcelUsingOpenXml.resx (9981, 2011-05-18)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml.sln (914, 2011-05-18)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml (0, 2011-05-20)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml\app.config (1547, 2011-05-09)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml\common (0, 2011-05-18)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml\common\OpenXmlMethod.vb (18099, 2011-05-18)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml\My Project (0, 2011-05-18)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml\My Project\AssemblyInfo.vb (1466, 2011-05-18)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml\My Project\Resources.Designer.vb (2418, 2011-05-18)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml\My Project\Resources.resx (5612, 2011-05-18)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml\My Project\Settings.Designer.vb (1603, 2011-05-18)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml\My Project\Settings.settings (1050, 2011-05-09)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml\Program.vb (409, 2011-05-18)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml\StyleExcelUsingOpenXml.Designer.vb (6544, 2011-05-18)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml\StyleExcelUsingOpenXml.resx (9981, 2011-05-18)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml\StyleExcelUsingOpenXml.vb (6495, 2011-05-18)
StyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml\VBStyleExcelUsingOpenXml.vbproj (7697, 2011-05-18)

====================================================================================== Windows APPLICATION: CSStyleExcelUsingOpenXml Overview ====================================================================================== ////////////////////////////////////////////////////////////////////////////////////// Summary: This sample demonstrates how to create a SpreadsheetWorkbook,make cell content bold, show Excel content on the AxSpreedsheet control and show cell format detail on Textbox control. This sample shows how to apply style to Excel2010 via OpenXML SDK. It also uses a lot of features about SpreadsheetML objects such as those included in the OpenXML SDK.Now I will introduce the architecture of Office XML Formats. The OpenXML format container is based on the simple and parts-based compressed ZIP file format specification. At the core of the new office XML Formats is the use of XML reference schemas and a ZIP container, Each file is comprised of a collection of any number of parts;this collection defines the document. Document parts are stored in the container file or package using the industry-standard ZIP format. Most parts are XML files that describe application data, metadata, and even customer data, stored inside the container file. Other non-XML parts may also be included within the container package. This includes such parts as binary files representing images or OLE objects embedded in the document. In addition, there are relationship parts that specify the relationships between parts; This design provides the structure for an Office file. While the parts make up the content of the file, the relationships describe how the pieces of content work together. The most critical thing is that this sample uses OpenXML SDK to manipulate Excel files,which looks like under an Excel Office component. ////////////////////////////////////////////////////////////////////////////////////// Demo: Step1. Download OpenXMLSDKTool.msi and XMLSDKv2.msi, and install them on your machine. These package mentioned above can be found as shown below: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&displaylang=en Step2. Build this project in VS2010. Step3. Run CSStyleExcelUsingOpenXml.exe. Step4. Left click "OpenXmlCreateExcelFile" to generate the "1.xlsx" excel file in the bin directory under your project. Step5. Left click "ShowExcelInControl" to copy Excel data content to AxSpeedSheet control, and you would see the "A1" cell's font without bold effects. Step6. Left click "SetCellBold" to make "A1" cell content bold. Step7. Left click "ShowExcelInControl" again, and you will see the "A1" cell's font has been bolded. Step8. Left click “ShowCellFormat” and you will see the cell format information presented in Textbox control. ////////////////////////////////////////////////////////////////////////////////////// Code Logic: 1. The sample uses OpenXml SDK 2.0 to achieve the function mentioned in the summary part.Open XML SDK 2.0 for Microsoft Office is built on the System.IO.Packaging API and provides strongly-typed classes to manipulate documents that adhere to Office OpenXML File formats specifications.It simplifies the task of manipulating Open XML packages, So you only add a reference into your project such as DocumentFormat.OpenXml and WindowBase. Then you can add a WorkbookPart to the document and so on. These operations strictly obey the Markup Languages such as SpreadSHeetML and its architecture. 2. The sample uses WorkbookStyplesPart Object and its child object to demonstrate how to get CellFormat and set its FillID,BorderID,FOrmatId,FontId, ApplyFont,Count and StyleIndex. Among them It is important that you set the two properties such as Count and StyleIndex. If these two properties are not correct, you can't represent it on the AxSpeedSheet or Excel Office component because of the xml architecture has been violated. Finally please remember that SpreadsheetDocument should be closed when all the operations has been completed. If not, you can't show Excel Content on the control or perform some other operations. 3. Moreover it should be mentioned that the sample use AxSpreadsheet to represent the excel content in order to compare the operation effort before making bold and after making bold.AxSpreadsheet should be involved in this project after you right click the "Choose Item..." menu item on the Toolbox. Consequently, you can find the Microsoft Office Spreadsheet 11.0 in the COM Components Tab Control. After performing the above action,feel free to represent the excel content in the Winform Windows.Finally, you should remember using these codes listed below to release the Excel Office Component otherwise your Task Manager will see increasing Excel processes and it will take up too much of your computer's valuable resources. // Release resource about Excel application. ThisWorkBook.Close(null, null, null); ThisApplication.Workbooks.Close(); ThisApplication.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(ThisApplication); System.Runtime.InteropServices.Marshal.ReleaseComObject(ThisSheet); System.Runtime.InteropServices.Marshal.ReleaseComObject(ThisWorkBook); ThisSheet = null; ThisWorkBook = null; ThisApplication = null; GC.Collect(); ////////////////////////////////////////////////////////////////////////////////////// References: Dive into SpreadsheetML (Part 1 of 2) http://msdn.microsoft.com/en-us/library/bb226687(office.11).aspx Format cells in Excel using C# http://social.msdn.microsoft.com/forums/en-us/winforms/thread/3CD3C58A-0148-4DFD-A5CE-2508996587AC Make cell content bold http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/410f87e7-9380-40bd-ad3d-d66cf2a4357b using the open xml format sdk 2.0 version... http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/c1a8c007-797a-4484-a746-ef59b48c0c2a Open XML SDK roadmap http://blogs.msdn.com/b/dmahugh/archive/2008/03/13/open-xml-sdk-roadmap.aspx Spreadsheets http://msdn.microsoft.com/en-us/library/cc850837.aspx Create spreadsheet with styles http://openxmldeveloper.org/forums/thread/7796.aspx in the spreadsheet i create a new font and want to set the FontId how to do it? http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/48017830-8139-49d4-a023-f3f3***043d5b Excel spreadsheet to Axspreadsheet http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/9ca844fb-bbf1-4ef3-8d0b-cadc32407c32 Simple SpreadsheetML file Part 3 - Formatting http://blogs.msdn.com/b/brian_jones/archive/2007/05/29/simple-spreadsheetml-file-part-3-formatting.aspx HOW TO generate Open XML file in C# in 4 minutes? http://blog.goyello.com/2009/08/21/how-to-generate-open-xml-file-in-c-in-4-minutes/ //////////////////////////////////////////////////////////////////////////////////////

近期下载者

相关文件


收藏者