I am using C++/CLI for a school project and I need to export some data into Excel format (xlsx). The problem is that this code has parts like AddNewPart that are underlined with red by Visual Studio (it says that the specified class has no member AddNewPart) but the code is compiled and the application runs but the result is a corrupted xlsx file (when I tried to open it with excel it says that is corrupt).
SpreadsheetDocument ^doc = SpreadsheetDocument::Create(path_get, SpreadsheetDocumentType::Workbook);
WorkbookPart ^wbookpart = doc->AddWorkbookPart();
wbookpart->Workbook = gcnew Workbook();
WorksheetPart^ worksheetPart = wbookpart->AddNewPart<WorksheetPart^>();
SheetData^ sheetData = gcnew SheetData();
worksheetPart->Worksheet = gcnew Worksheet();
worksheetPart->Worksheet->AppendChild(sheetData);
Sheets^ sheets = doc->WorkbookPart->Workbook->AppendChild<Sheets^>(gcnew Sheets());
Sheet^ sheet = gcnew Sheet();
sheet->Id = doc->WorkbookPart->GetIdOfPart(worksheetPart);
sheet->SheetId = 1;
sheet->Name = "mySheet";
sheets->Append(sheet);
wbookpart->Workbook->Save();
doc->Close();
I had the same problem as you, Visual Studio reports that the class has no member, but it still compiles and still seems to populate the parameters for me. Try stepping through with the debugger and see if this is the same for you. If I try to rename AddNewPart to something that definitely doesn't exist, it doesn't compile for me.
As a less complicated check, GetIdOfPart is also reporting the same error message for me, but that parameter definitely fills in on the debugger despite visual studio claiming the class has no member.
Related
Currently in Web-Essentials (for Visual Studio 2015), if a .ts file from the Solution Explorer is dragged and dropped into an open .ts file, a reference path is automatically inserted at the top:
/// <reference path="../playback/key.ts" />
This is fine when a project is being developed using internal modules (namespaces), but is virtually useless when going external. How could I make it so that an ES6 import statement is generated instead? That would be awesome. Such as:
import {} from "../playback/key";
It turns out what we are seeing is a built-in feature of Web-Essentials. I've filed a feature-request to get this available, hopefully in the near future.
In the meantime, the following Visual Commander automation snippet can replace all references to ES6 imports:
using EnvDTE;
using EnvDTE80;
using System.Text.RegularExpressions;
public class C : VisualCommanderExt.ICommand
{
// Called by Visual Commander extension.
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
TextDocument doc = (TextDocument)(DTE.ActiveDocument.Object("TextDocument"));
var p = doc.StartPoint.CreateEditPoint();
string s = p.GetText(doc.EndPoint);
p.ReplaceText(doc.EndPoint, this.ReplaceReferences(s), (int)vsEPReplaceTextOptions.vsEPReplaceTextKeepMarkers);
}
// Converts "reference" syntax to "ES6 import" syntax.
private string ReplaceReferences(string text)
{
string pattern = "\\/\\/\\/ *<reference *path *= *\"([^\"]*)(?:\\.ts)\" *\\/>";
var regex = new Regex(pattern);
var matches = Regex.Matches(text, pattern);
return Regex.Replace(text, pattern, "import {} from \"./$1\";");
}
}
The regex used to perform this replace is (without the double backslashes, more readable):
\/\/\/ *<reference *path *= *"([^"]*)(?:\.ts)" *\/>
This snippet will effectively convert all reference comments to ES6 imports in the currently active document, very useful.
Known issues:
a comment containing a reference tag is not recognized by Visual Studio if it is preceded by other text in the corresponding line, but it is still replaced by this snippet
additional text after a reference tag is valid, but after replace will cause syntax errors, since it is no longer a comment.
(Neither of these issues are relevant if the snippet is used on reference tags generated by Web-Essentials when a .ts file is drag-and-dropped.)
I need to find a way to "print" a SrsReport, in my case SalesInvoice, as .PDF (or any kind of file) to a specific location.
For this I modified the SRSPrintDestinationSettings to output the SalesInvoice-Report as a .PDF:
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(#'\\AXDEV\Bottomline\Test\test.pdf');
Somehow this gets ignored and I recive a Email with the report as .PDF attached.
For example this will run on ax 2012 but won't print to PDF for me.
SRSPrintDestinationSettings settings;
CustInvoiceJour custInvoiceJour;
SrsReportRunController controller = new SrsReportRunController();
PurchPurchaseOrderContract rdpContract = new PurchPurchaseOrderContract();
SalesInvoiceContract salesInvoiceContract = new SalesInvoiceContract();
select firstOnly1 * from custInvoiceJour where custInvoiceJour.SalesId != "";
// Define report and report design to use
controller.parmReportName(ssrsReportStr(SalesInvoice,Report));
// Use execution mode appropriate to your situation
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
rdpContract.parmRecordId(custInvoiceJour.RecId);
controller.parmReportContract().parmRdpContract(rdpContract);
// Explicitly provide all required parameters
salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); // Record id must be passed otherwise the report will be empty
controller.parmReportContract().parmRdpContract(salesInvoiceContract);
salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo()); // comment this code if tested in pre release
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(#'\\AXDEV\Bottomline\Test\test.pdf');
//tokens = settings as SrsPrintDestinationTokens();
//controller.parmPrintDestinationTokens(null);
//Suppress report dialog
controller.parmShowDialog(false);
// Execute the report
controller.startOperation();
Questions:
Is this the correct way to print a srsReport to .pdf?
Am I passing/setting the printerSettings correctly?
Where does it say "Send Email"?
EDIT: Code is working fine. We are using external code of a company which simply doesnt implement this.
Use the cleaner code of Alex Kwitny
Here is working code for me. I just quickly coded this from scratch/memory based off of glancing at yours, so compare for differences.
I have two things marked (1) and (2) for you to try with your code, or just copy/paste mine.
static void JobSendToPDFInvoice(Args _args)
{
SrsReportRunController controller = new SrsReportRunController();
SRSPrintDestinationSettings settings;
CustInvoiceJour custInvoiceJour = CustInvoiceJour::findRecId(5637925275);
SalesInvoiceContract salesInvoiceContract = new SalesInvoiceContract();
Args args = new Args();
controller.parmReportName(ssrsReportStr(SalesInvoice, Report));
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
controller.parmShowDialog(false);
salesInvoiceContract.parmRecordId(custInvoiceJour.RecId);
salesInvoiceContract.parmDocumentTitle(CustInvoiceJour.InvoiceId);
salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());
// (1) Try by passing args
args.record(custInvoiceJour);
args.parmEnum(PrintCopyOriginal::Original);
args.parmEnumType(enumNum(PrintCopyOriginal));
controller.parmReportContract().parmRdpContract(salesInvoiceContract);
controller.parmArgs(args);
// (2) Try explicitly preventing loading from last value
// controller.parmLoadFromSysLastValue(false);
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(#'C:\Temp\Invoice.pdf');
controller.startOperation();
}
Since you are talking about the sales invoice the report is using the print management feature and you cannot simply override the print settings like that.
You need to override the runPrintMgmt on the controller class and determine there whether you want default print management or your own code.
See this post for an example: http://www.winfosoft.com/blog/microsoft-dynamics-ax/manipulating-printer-settings-with-x
I am trying to make a WYSIWYG HTML-editor by embedding GeckoFX in a Windows Forms application in VB.NET.
The code goes like this:
Dim Gbrowser As New GeckoWebBrowser
Gbrowser.Navigate("about:blank")
...
Gbrowser.Navigate("javascript:void(document.body.contentEditable='true')")
How can I activate and access the nsIHTMLEditor interface from within my application?
Thank you.
UPDATE
This code does not work:
Dim hEditor As nsIHTMLEditor
hEditor = Xpcom.GetService(Of nsIHTMLEditor)("#mozilla.org/editor/htmleditor;1")
hEditor = Xpcom.QueryInterface(Of nsIHTMLEditor)(hEditor)
hEditor.DecreaseFontSize()
Error in the last line: HRESULT E_FAIL has been returned from a call to a COM component.
nsIHTMLEditor is likely a per browser instance rather than a global instance (like things returned by Xpcom.GetService)
One can get a nsIEditor like this by (by supplying a Window instance)
var editingSession = Xpcom.CreateInstance<nsIEditingSession>("#mozilla.org/editor/editingsession;1");
nsIEditor editor = editingSession.GetEditorForWindow((nsIDOMWindow)Window.DomWindow);
Marshal.ReleaseComObject(editingSession);
(or you can just call the nsIEditor GeckoWebBrowser.Editor property.)
You may be able to cast this nsIEditor to a nsIHtmlEditor (although I have yet to try it)
GeckoWebBrowser browser = .....;
// Untested code
nsIHTMLEditor htmlEditor = (nsIHTMLEditor)browser.Editor;
Update:
The VB code from #GreenBear
Dim gEditor As nsIHTMLEditor:
gEditor = Gbrowser.Editor:
gEditor.DecreaseFontSize()
I am trying to create a small GUI that will rename a file (eventually a batch of files). I am using C++ and Windows user (Visual Studio Community 2015).
I have a btnSelectFiles button with which I want to open a file selection GUI.
I am trying to use openFileDialog but am struggling to set the file name to a string variable.
The code I am using:
public:
void btnSelectFiles_Click(Object^ /*sender*/, System::EventArgs^ /*e*/)
{
IO::Stream^ myStream;
OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
openFileDialog1->InitialDirectory = "c:\\";
openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1->FilterIndex = 2;
openFileDialog1->RestoreDirectory = true;
if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
if ((myStream = openFileDialog1->OpenFile()) != nullptr)
{
// Insert code to read the stream here.
myStream->Close();
}
}
/*String test = openFileDialog1;*/
}
One of my many tries was to use:
String test = openFileDialog1
I also tried:
String test = openFileDialog1.FileName
But received an expression must have class type error.
Please can someone help me solve this and thus help my understanding on the matter. The book I have picked up does not cover this and I have struggled to find help online.
Since you are using c++/CLI ( rather than C++ ) you must write
String^ test = new String( openFileDialog1.FileName );
I have a JScript script that runs using cscript.exe. It creates a shortcut on the desktop (and in the start menu) that runs cscript.exe with parameters to run another JScript script. It looks, in relevant part, like this:
function create_shortcut_at(folder, target_script_folder)
{
var shell = new ActiveXObject("WScript.Shell");
var shortcut = shell.CreateShortcut(folder + "\\Run The Script.lnk");
shortcut.TargetPath = "cscript";
shortcut.Arguments = "\""+target_script_folder+"\\script.js\" /aParam /orTwo";
shortcut.IconLocation = target_script_folder+"\\icon.ico";
shortcut.Save();
}
It gets called like create_shortcut_at(desktop_folder, script_folder).
And that works, as far as it goes. It creates the desktop icon, pointing properly to the script and runs it when double-clicked. The problem is that it really needs to run the script "as administrator".
And the script really does need to run "as administrator" -- it installs applications (for all users) and reboots the computer. (For those interested, the script is wpkg.js. Modifying it to self-elevate is undesirable.)
Since the target of the shortcut is actually "cscript.exe", I can't use a manifest for the escalation. I could probably theoretically install a cscript.exe.manifest in the windows directory, but even if that worked, it would be a terrible idea for reasons that are obvious.
I'd also prefer not to use a dummy script, since that is an extra file to deal with and there's another, seemingly reasonable, solution at hand: check the "Run as administrator" box on the shortcut.
Thirty-seconds of investigation reveals that the WScript.Shell ActiveX Object does not have the interfaces required for this. Additional investigation suggests that IShellLinkDataList does. However, IShellLinkDataList is a generic COM Interface. I see several examples around the Internet, most linking here. However, all the examples do it in compiled code (C++, C#, even JScript.NET). I significantly prefer to be able to do it directly in JScript, running from cscript.exe.
That said, I'm all for ideas I didn't contemplate or other solutions.
The official way to mark a shortcut file as requiring elevation is via IShellLinkDataList. It's difficult to use that interface from an automation environment.
But, if you are happy with a hack, you can do it in script, just by flipping a bit in the .lnk file.
When you tick the "run as administrator" box in the Advanced tab of the Shell Properties box, or when you use IShellLinkDataList to set the flags to include SLDF_RUNAS_USER, you're basically just setting one bit in the file.
You can do that "manually" without going through the COM interface. It's byte 21, and you need to set the 0x20 bit on.
(function(globalScope) {
'use strict';
var fso = new ActiveXObject("Scripting.FileSystemObject"),
path = "c:\\path\\goes\\here\\Shortcut2.lnk",
shortPath = path.split('\\').pop(),
newPath = "new-" + shortPath;
function readAllBytes(path) {
var ts = fso.OpenTextFile(path, 1), a = [];
while (!ts.AtEndOfStream)
a.push(ts.Read(1).charCodeAt(0));
ts.Close();
return a;
}
function writeBytes(path, data) {
var ts = fso.CreateTextFile(path, true),
i=0, L = data.length;
for (; i<L; i++) {
ts.Write(String.fromCharCode(data[i]));
}
ts.Close();
}
function makeLnkRunAs(path, newPath) {
var a = readAllBytes(path);
a[0x15] |= 0x20; // flip the bit.
writeBytes(newPath, a);
}
makeLnkRunAs(path, newPath);
}(this));
ps:
function createShortcut(targetFolder, sourceFolder){
var shell = new ActiveXObject("WScript.Shell"),
shortcut = shell.CreateShortcut(targetFolder + "\\Run The Script.lnk"),
fso = new ActiveXObject("Scripting.FileSystemObject"),
windir = fso.GetSpecialFolder(specialFolders.windowsFolder);
shortcut.TargetPath = fso.BuildPath(windir,"system32\\cscript.exe");
shortcut.Arguments = "\"" + sourceFolder + "\\script.js\" /aParam /orTwo";
shortcut.IconLocation = sourceFolder + "\\icon.ico";
shortcut.Save();
}