Using the OpenXML SDK 2.0 :
- Create your macro and save it in .xlsm format, say snorehorse.xlsm.
- Open snorehorse.xlsm in the Productivity Toolkit OpenXML and make the reflection code in the root of the tree.
- Find the macro binary code. It is in string format and looks like random characters.
- IDE OpenXML SDK excel, .
- , №3, .
- vba .
- vba.
- , .
:
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
private string partData = "...";
public void vbaInjector{
[code to create / open spreadsheet using OpenXML omitted]
VbaProjectPart vbaProjectPart1 = snoreSpreadsheetDoc.WorkbookPart.AddNewPart<VbaProjectPart>("rId8");
System.IO.Stream data = GetBinaryDataStream(partData);
vbaProjectPart1.FeedData(data);
data.Close();
[code to close spreadsheet and cleanup omitted]
}
private System.IO.Stream GetBinaryDataStream(string base64String)
{
return new System.IO.MemoryStream(System.Convert.FromBase64String(base64String));
}
DLL OpenXML SDK , SDK.
, , XML, OpenXML SDK, . - , .
, VBA script Excel, , . .
.