I need to lock a particular cell value in an Excel file using OfficeWriter. Is this possible? If so, what API calls do I need to use?
Locking a cell with OfficeWriter is the same as it is in Excel: all cells have a 'locked' property as part of their style. The locked property is set to true by default, but does not take affect until the worksheet is protected.
ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Create(ExcelApplication.FileFormat.Xlsx);
Worksheet ws = wb.Worksheets[0];
//Protecting the sheet will lock any cells
//that have the locked property set to true
ws.Protect("MyPassword");
To leave certain cells unlocked, create a style where the locked property is set to false. Then apply the style to the cells you wish to leave unlocked.
ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Create(ExcelApplication.FileFormat.Xlsx);
Worksheet ws = wb.Worksheets[0];
//Create the 'unlocked' style
Style unlockedStyle = wb.CreateStyle();
unlockedStyle.CellLocked = false;
//Apply to any cells you wish to leave unlocked
//when the worksheet is protected
ws.Cells["A1"].Style = unlockedStyle;
ws.Cells["B1"].Style = unlockedStyle;
//Protecting the sheet will lock any cells
//that have the locked property set to true
ws.Protect("MyPassword");
We have some additional related information on protecting worksheets in our documentation: http://wiki.softartisans.com/display/EW8/Protecting+Your+Worksheet
Note, I work for SoftArtisans, makers of OfficeWriter.
Related
I face a little problem with libreoffice calc v5.1.6.2 as I didn't managed to find how to show / hide a button on a sheet using macros.
I'm talking about buttons directly on the sheet, not the dialog ones (haven't tested on dialogs yet, maybe it will be the same problem...).
So I can enable / disable them by using something like:
MyButton.enabled = True (or False)
after I populated "MyButton" with the right object, but there is no
MyButton.visible = False
or
MyButton.isVisible = False
Despite the fact the "visible" property exists in the editor, right below the "enabled" line in design mode. So how can I acheive that dynamically?
XrayTool shows a property with the somewhat unusual name of EnableVisible.
oSheet = ThisComponent.CurrentController.ActiveSheet
oButton = oSheet.DrawPage.Forms.getByIndex(0).getByName("Push Button 1")
oButton.EnableVisible = False 'Hide the button
For this to work, Calc's Design Mode must be off. If it is on, then all buttons will be shown regardless of their visibility setting.
Note: I could not find this property in the API docs.
Is there a way to modify the background color in Outlook inbox listing of e-mails (MailItem instances) programmatically? I'd like to create an add-in that will allow me to color-code my emails according to some rules.
I've went through MailItem properties in the documentation, but wasn't able to find anything display-format related.
The MailItem class doesn't provide anything for that. Instead, you need to customize the view in Outlook.
You can use the CurrentView property of the Folder or Explorer class to get a View object representing the current view. To obtain a View object for the view of the current Explorer, use Explorer.CurrentView instead of the CurrentView property of the current Folder object returned by Explorer.CurrentFolder.
The View object allows you to create customizable views that allow you to better sort, group and ultimately view data of all different types. There are a variety of different view types that provide the flexibility needed to create and maintain your important data.
The table view type (olTableView) allows you to view data in a simple field-based table.
The Calendar view type (olCalendarView) allows you to view data in a calendar format.
The card view type (olCardView) allows you to view data in a series of cards. Each card displays the information contained by the item and can be sorted.
The icon view type (olIconView) allows you to view data as icons, similar to a Windows folder or explorer.
The timeline view type (olTimelineView) allows you to view data as it is received in a customizable linear time line.
Views are defined and customized using the View object's XML property. The XML property allows you to create and set a customized XML schema that defines the various features of a view.
Private Sub FormatHandoffMessages()
Dim objView As TableView
Dim objRule As AutoFormatRule
' Check if the current view is a table view.
If Application.ActiveExplorer.CurrentView.ViewType = olTableView Then
' Obtain a TableView object reference to the current view.
Set objView = Application.ActiveExplorer.CurrentView
' Create a new rule that displays any message with a
' subject line that starts with "HANDOFF" in
' blue, bold, 8 point Courier New text.
Set objRule = objView.AutoFormatRules.Add("Handoff Messages")
With objRule
.Filter = """http://schemas.microsoft.com/mapi/proptag/0x0037001f""" & _
" CI_STARTSWITH 'HANDOFF'"
With .Font
.Name = "Courier New"
.Size = "8"
.Bold = True
.Color = olColorBlue
End With
End With
' Save and apply the table view.
objView.Save
objView.Apply
End If
End Sub
I have created a NatTable with a RowSelectionModel and a RowSelectionProvider:
dataProvider = new ListDataProvider<>(rowData, columnAccessor);
bodyDataLayer = new DataLayer(dataProvider);
glazedListEventsLayer = new GlazedListsEventLayer<>(bodyDataLayer, rowData);
columnReorderLayer = new ColumnReorderLayer(glazedListEventsLayer);
columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
selectionLayer = new SelectionLayer(columnHideShowLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
selectionProvider = new RowSelectionProvider<>(selectionLayer, dataProvider, true);
selectionLayer.setSelectionModel(new RowSelectionModel<>(selectionLayer, dataProvider, idAccessor, false));
Basically, the table does what I want it to do. There is but one exception:
The table looks like this:
As intended, the table shows the row as selected (1). Also it highlights the actually selected cell (2), which is very nice. But, it renders the whole table column header as selected (3). I don't want that. I want either not highlight the header cells at all, or (even better:) I'd like only the column header cell of the cursor-cell (2) to be highlighted.
I thought that maybe there is a configuration label attached to the column header cells which results in the highlighting (so I could just change the style for this kind of label to get rid of the highlighting), but COLUMN_HEADER is the only configuration label, I can see when debugging.
So, I am bit stuck now. What causes the header cells to be highlighted and how can I change this behavior? Is it possible to highlight only the header of the cursor cell (as is done with the selected row's cursor cell (2))?
It is not the label you need to check, for selection it is the DisplayMode. So to not render the column header highlighted if you select a row you need to register the same style configuration for DisplayMode.SELECT as you register for DisplayMode.NORMAL.
If you only want to highlight the selection anchor in the column header you will need to register a custom IConfigLabelAccumulator to the DataLayer of the column header that is connected to the SelectionLayer and adds a custom label in case the cell in the column header is in the same column as the selection anchor.
For only highlighting the selection anchor, there is no default in NatTable itself. Although it should be easy to add. Feel free to create an enhancement ticket for this and even contribute. :)
Im trying to cut down on the clutter of my form since the data im getting can fill in more or less fields from my table.
as of right now im trying to build an event but I do not know the right syntax to use to create my event.
right now i have:
= if toggle.onclick ="yes" then
data.visible=true
else
data.visible=false
end if
in the After Update tab of the Event tab.
I hope that gives you an idea of what im trying to do.
I have this on a test form so the only objects are:
checkbox name "toggle"
textbox name "data"
the text box is default to not visible at the moment.
my goal is to have a list of check boxes and once they are checked their corresponding text box would appear on a refresh. this way the workers wont be intimidated by the amount of textboxes are on my current form. also will reduce the vast clutter on the current form.
By default, the 'Toggle' value will be True or False - not 'yes' or 'no'. Thus the following is what you need to toggle fields:
Private Sub Toggle_AfterUpdate()
If Me.Toggle = True Then
Me.Data.Visible = True
Else
Me.Data.Visible = False
End If
End Sub
In Access 2010, I've built a calendar Form that I want to be able to display who is off in a given month.
Each box of the calendar obviously represents a different day. I've got a table called "Separated" set up that ultimately stores the associate name and the date they are off -- one day per record.
Here's what I've done so far to try to test it on just one of the boxes (representing a day):
Private Function fillDays()
Dim rsNames As DAO.Recordset
Set rsNames = CurrentDb.OpenRecordset("SELECT * FROM Separated")
If Not rsNames.EOF Then
b0.Text = rsNames![Associate]
End If
Set rsNames = Nothing
End Function
I get the following debug note:
"Run-Time Error '2185"
"You can't reference a property or method for a control unless the control has the focus."
The debugger highlights the line with "b0.text = rsNames![Associate]
Is there some whay that I need to reference an index number from my "Separated" table?... or perhaps using a query method of some sort would be more effecient.
Assuming b0 is a textbox, the error you are getting is due to the fact that you can't use it's Text property when said textbox hasn't got the focus.
As stated in MSDN, «While the control has the focus, the Text property contains the text data currently in the control; the Value property contains the last saved data for the control. When you move the focus to another control, the control's data is updated, and the Value property is set to this new value. The Text property setting is then unavailable until the control gets the focus again» (emphasis mine).
Try using Value (help here) instead:
b0.Value = rsNames![Associate]