Excel with Interop in C#, how to hide the menu bar which remains displayed - menu

I'm developing an application that needs to launch Excel, but the client wants Excel to be hidden. So far nothing very complicated, but when I launch Excel a 2nd "detached" menu bar is displayed (see the photo below), even when I hide Excel, this bar is visible.
Is there a way to not show it at all? Even if I want to show Excel for debugging?
Here is the bar:
enter image description here
I specify that when I open Excel normally, I do not have this additional menu bar.
I also specify that I launch a macro in Excel (it launches me solvers This is why I use Excel).
Code for open application:
private bool InitExcel(bool Visible)
{
try
{
//Démarre Excel et récupère l'application
_ApplicationXL = new Microsoft.Office.Interop.Excel.Application();
_LesWorkBooks = _ApplicationXL.Workbooks;
_ApplicationXL.Visible = Visible;
return true;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return false;
}
}
Thanks
I just use :
_ApplicationXL.Visible = Visible;
This hides excel well, but the bar remains displayed. Is a cause of using the macro to start Solvers, macro in VBA?

Related

MFC MDI dynamically changing tab style from a property dialog

It has been 10 months since I worked on my app due to a death in the family, just started looking at it again and still not sure how to solve the problem.
The project inquires/help started here:
MFC MDI Collecting control states for the "apply" button routine
Since this is a specific focused question, I didn't want to muck up my other thread, so what I'd like to do is change the documents tab styles after the view is loaded. I know that this can be done because the master repository from Microsoft with all the code examples has a project called VCSamples-master\VCSamples-master\VC2010Samples\MFC\Visual C++ 2008 Feature Pack\TabControl which I have looked at. It dawns on me that even though I can follow its code, the calls are from within the MDI window itself where my issue is I'm trying to do this via a property page dialog using OnApply which changes things.
I was able to do part of this properly with the help of the thread above to the OutputPane successfully because I was able to get the Pane handle and execute. I was told that for the MDI tabs after creation that I need to parse the tabs, count them, and then execute. So my issue here is after I capture the tabs......how to change their styles.
Here is the code as it stands:
BOOL CSettingsUserTabs::OnApply()
{
BOOL bResult = CMFCPropertyPage::OnApply();
if (bResult)
{
// Update Output Pane Tab Styles (Works 100%)
AfxGetApp()->WriteProfileInt(_T("Settings"), _T("UserTabStyle"), m_style_tabs); // Save value to registry
((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);
((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.RecalcLayout();
//Get the open file tabs in the MDI
for (POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition(); pos != NULL; )
{
CDocTemplate* pTempl = AfxGetApp()->GetNextDocTemplate(pos);
for (POSITION pos1 = pTempl->GetFirstDocPosition(); pos1 != NULL; )
{
CDocument* pDoc = pTempl->GetNextDoc(pos1);
for (POSITION pos2 = pDoc->GetFirstViewPosition(); pos2 != NULL; )
{
CView* pView = pDoc->GetNextView(pos2);
if (pView->IsKindOf(RUNTIME_CLASS(CTrainView)))
{
// THIS IS WHERE MY ISSUE IS, NOW THAT ALL THE TABS ARE
// CAPTURED, HOW DO I ADDRESS THEM LIKE WHAT IS SHOWN
// ABOVE:
//((CMainFrame*)AfxGetMainWnd())->xxxxxx.yyyyyy.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);
}
}
}
}
}
return bResult;
}
If I can figure this last piece out, I'll be basically finished, I just can't seem to find a solution on how to do this via property sheet via OnApply.
Any suggestions or actual code examples I can see to solve my problem?
FYI: No, I haven't had any time to take additional OOP to solve this. I'm hoping someone can provide some guidance so I can move on after getting this sorted.
Thanks,
Chris
EDIT 1:
So I took a closer look at Constantine's suggestion and here is what I came up with:
BOOL CSettingsUserTabs::OnApply()
{
BOOL bResult = CMFCPropertyPage::OnApply();
if (bResult)
{
// Update Output Pane Tab Styles
AfxGetApp()->WriteProfileInt(_T("Settings"), _T("UserTabStyle"), m_style_tabs); // Save value to registry
((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);
((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.RecalcLayout();
CMFCTabCtrl& MDI_STYLES = ((CMainFrame*)AfxGetMainWnd())->GetMDITabs();
MDI_STYLES.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);
MDI_STYLES.RecalcLayout();
CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, GetTopLevelFrame());
pMainFrame->SetFocus();
pMainFrame->RecalcLayout();
}
return bResult;
}
The m_styles_tabs is getting the index value of 0-8 when I select the radio button. The code compiles and runs and I see the index value change when I break on it, but the tabs for the MDI are still not updating. Does the edited code make sense based on the members shown here:
https://learn.microsoft.com/en-us/cpp/mfc/reference/cmfctabctrl-class?view=msvc-170#modifytabstyle
I think this the right direction, am I missing something?

Apache POI - watermark in Excel - different appearence in Excel and LibreOffice

I follow the sample and add pictures as watermark like the following:
private void addWaterMark4AllSheets() {
final BufferedImage image = FontImage.createWatermarkImage();
// Export to byte stream B
final ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
ImageIO.write(image, "png", os);
} catch (final IOException e) {
e.printStackTrace();
}
final XSSFWorkbook wb = (XSSFWorkbook) workBook;
final int pictureIdx = wb.addPicture(os.toByteArray(), Workbook.PICTURE_TYPE_PNG);
final POIXMLDocumentPart poixmlDocumentPart = wb.getAllPictures().get(pictureIdx);
// ((XSSFSheet )(schreiben.getSheet()).
for (int i = 0; i < workBook.getNumberOfSheets(); i++) {// Get each Sheet
final XSSFSheet sheet = wb.getSheetAt(i);
final PackagePartName ppn = poixmlDocumentPart.getPackagePart().getPartName();
final String relType = XSSFRelation.IMAGES.getRelation();
// add relation from sheet to the picture data
final PackageRelationship pr = sheet.getPackagePart().addRelationship(ppn, TargetMode.INTERNAL, relType,
null);
// set background picture to sheet
sheet.getCTWorksheet().addNewPicture().setId(pr.getId());
}
}
In general the approach works quite fine. A picture is added into the Excel. But the appearance is different.
In Excel: the image is displayed in the background during the editing (of the sheets). But it is NOT displayed when I print the sheet.
In LibreOffice (7.1): the image is NOT displayed during the editing (of the sheet) - but is printed.
Is there a chance to fix it for working in both Spreadsheets?
There is nothing what apache poi could change as this behavior is by design in the different spreadsheet softwares.
Your linked code example does not creating watermarks. Watermark functionality is not available in Microsoft Excel. Instead it adds background pictures to sheets.
Microsoft itself states: You cannot print a background graphic for a Excel worksheet. So using Microsoft Excel the sheets background graphics only are visible in Excel GUI but not in prints.
In LibreOffice those background graphics are called watermarks but Libreoffice states in Defining Graphics or Colors in the Background of Pages (Watermark):
In spreadsheets this background appears only in the print behind the
cells not formatted elsewhere.
So using Libreoffice the sheets background graphics are visible in prints only.
So what you had observed is by design.
In Add or remove a sheet background Microsoft describes methods to mimic a watermark in Excel. The usage of a picture in a header or footer to mimic a watermark using apache poi is described in apache POI adding watermark in Excel workbook. But this also means a print watermark. So the watermark is visible in print preview and print only. It is not visible in sheet's GUI. And the option to add picture in a header or footer to mimic a watermark is Excel only. LibreOffice does not provide that feature.
Conclusion:
There is not a possibility to have a functionality similar to a watermark which works in Excel and LibreOffice the same way.

Select all content when Tabulator editor opens

I have a Tabulator (4.9.3) with values that use an editor of type text. As I tab through the table, I want each value to be selected so I can overwrite it without having to clear it first. I have tried putting the usual range selection code into the cellEditing callback and the Tabulator source code where the input gets created. Here is one variation of the code (I can't show them all because the node differs based on context):
try {
if (document.selection) {
// IE
var range = document.body.createTextRange();
range.moveToElementText(input);
range.select();
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(input);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
}
} catch (e) {console.log(e);}
If I double-click on the cell, the value selects as desired. How can I get this to work with keyboard navigation as well?
Since the editor is not assigned an id, finding a selector that could find it reliably was problematic without editing the source code. Since I was going to have to edit the source, I ended up adding the following line to the onRendered function of the input element under Edit.prototype.editors.
input.select();

A problem for selecting a image from the imagepupop dialog

One more question. If I create a image-popup dialog, I find it only works when the frontimage (the top one in the image list). If other image is selected, the program will report "the image used in the expression does not exist". I can not understand the logic behind this error.
The following is a modified code pasted in the answer of the previous question. It can work well if the first image is selected, but the error message appears if the second image is selected.
I use GSM 2.30.xxxx
Class CMyDLG : UIframe
{
TagGroup DLG,DLGItems,imgPop
object Init(object self)
{
DLG = DLGCreateDialog("Test",DLGItems)
imgPop = DLGCreateImagePopup()
DLGItems.DLGAddElement( imgPop )
return self.super.init(DLG)
}
image GetSelectedImage( object self )
{
string selectedImageLabel
imgPop.DLGGetValue(selectedImageLabel) //DLGGetValue can return the label of the image diretly
Result("\n" + selectedImageLabel)
// From the string, get the label
//string label = selectedImageLabel.left( selectedImageLabel.find(":") )
//Result("\n" + label)
// From label, return image
//return FindImageByLabel(label)
return FindImageByLabel(selectedImageLabel)
}
}
// main
{
object dlg = Alloc(CMyDLG).Init()
dlg.Pose()
image selected = dlg.GetSelectedImage()
if ( selected.ImageIsValid() )
{
selected.SetName( "Selected" + random())
selected.ShowImage()
}
else Throw( "Error, nothing selected." )
}
Using the test code on GMS 3.3 it works except for the bug mentioned. I presume it's the same for GMS 2.3 but I haven't verified.
To make sure we test the same thing, here are exact instructions and a break-down:
Start out with two images A and B and A being front-most.
Run script
Don't change anything in the dialog
Press OK
ERROR
The dialog - taggroup does not (yet) hold any value. It possibly should, I consider this a bug.
Start out with two images A and B and A being front-most.
Run script
Click the selection box and select "A" from the drop-down
Press OK
A is correctly selected
Start out with two images A and B and A being front-most.
Run script
Click the selection box and select "B" from the drop-down
Press OK
ERROR
The dialog - taggroup does not (yet) hold any value. It definitly should, I consider this a bug. It is most likely what you were describing?
Start out with two images A and B and A being front-most.
Run script
Click the selection box and select "A" from the drop-down
Click the selection box and select "B" from the drop-down
Press OK
B is correctly selected
To summarize:
Yes, there is a bug and nothing wrong with your script.
The selection box only works after selecting an items for the second time.
The example code (first script) in this answer seems to work on any of the open images when selected.
However, there is the (mentioned) bug that it does not work on first selection, only when you select one image and then another.
If your code fails, please provided a slimmed-down code-example of the failing code so that a mistake can possibly be spotted.

click on button which appears sometime on screen using python selenium

I am working automating website which generates quotations for mixer selection, sometimes for some parameters list of mixers suggested is more than 5 then Next button appears below the list. This button shown on the screen only when mixer list is more than 5.
below code I am using to save screenshot of the page and I want to screenshot of page which will come after click on Next button whenever it is available.
name = str(worksheet.cell_value(1,1))+"_"+str(worksheet.cell_value(1,2))+"_"+str(worksheet.cell_value(1,3))+\
"_"+str(worksheet.cell_value(1,4))+str(worksheet.cell_value(1,5))+".png"
driver.save_screenshot("D:\Automation\Pycharm_project\MRMix\Screenshots\%s"%name)
Lets say if next button is displayed, then need to click on it and need to take screenshot. You can simply try like below (in java)
you can have small method to return true or false depends on next button display
boolean isNextDisplay=false;
try {
if(driver.findElement(By.id("nextButton")).isDisplayed()==true) {
isNextDisplay=true;
}
}catch (Exception e) {
System.out.println("next button not displayed");
}
depends on display, click on next button and take screenshot.
if(isNextDisplay==true) {
//click on next button
//take screenshot
}
instead of methods, you can straightway write it. in Try >>If >> click and take screenshot

Resources