Is there a way to set specify where to break the page using EEPlus? I have the following code that sets the printer properties but haven't found a way to set a break point on a certain column.
// Set printer settings
ws.PrinterSettings.PaperSize = ePaperSize.Tabloid;
ws.PrinterSettings.Orientation = eOrientation.Landscape;
ws.PrinterSettings.FitToPage = true;
ws.PrinterSettings.FitToHeight = 1;
ws.PrinterSettings.FooterMargin = .05M;
ws.PrinterSettings.TopMargin = .05M;
ws.PrinterSettings.LeftMargin = .05M;
ws.PrinterSettings.RightMargin = .05M;
Edit (this helped solve my problem)
ws.Column(30).PageBreak = true;
ws.PrinterSettings.PaperSize = ePaperSize.A3;
ws.PrinterSettings.Orientation = eOrientation.Landscape;
ws.PrinterSettings.Scale = 75;
Just need to get reference to the Row and/or Column objects:
ws.Row(20).PageBreak = true;
ws.Column(2).PageBreak = true;
But keep in mind that FitToPage might suppress these.
Related
When programmatically generating a "normal" Excel sheet, a Range's PageBreak property can be set to xlPageBreakManual and then you can specify where the page is to break with code like so:
workbook.Worksheets[0].VPageBreaks.Add(sheet.Range["G1"]);
...but is this possible when printing a PivotTable? I would think not, since the PivotTable is fed from a datasource (a page of "raw data" in my case, which I subsequently hide), but if it is, I would like to know how.
This is what I do now to prepare the PivotTablized sheet for printing:
private void FormatPivotTable()
{
. . .
ConfigureForPrinting(_xlPivotTableSheet.UsedRange.Rows.Count);
}
private void ConfigureForPrinting(int finalRow)
{
string lastColumn = GetExcelTextColumnName(_xlPivotTableSheet.UsedRange.Columns.Count);
string printArea = String.Format("A1:{0}{1}", lastColumn, finalRow);
_xlPivotTableSheet.PageSetup.PrintArea = printArea;
_xlPivotTableSheet.PageSetup.Orientation = XlPageOrientation.xlLandscape;
_xlPivotTableSheet.PageSetup.Zoom = false;
_xlPivotTableSheet.PageSetup.FitToPagesWide = 1;
_xlPivotTableSheet.PageSetup.FitToPagesTall = 50;
_xlPivotTableSheet.PageSetup.LeftMargin = _xlApp.Application.InchesToPoints(0.5);
_xlPivotTableSheet.PageSetup.RightMargin = _xlApp.Application.InchesToPoints(0.5);
_xlPivotTableSheet.PageSetup.TopMargin = _xlApp.Application.InchesToPoints(0.5);
_xlPivotTableSheet.PageSetup.BottomMargin = _xlApp.Application.InchesToPoints(0.5);
_xlPivotTableSheet.PageSetup.HeaderMargin = _xlApp.Application.InchesToPoints(0.5);
_xlPivotTableSheet.PageSetup.FooterMargin = _xlApp.Application.InchesToPoints(0.5);
string rangeToRepeat = string.Format("$A$6:${0}$7", lastColumn);
_xlPivotTableSheet.PageSetup.PrintTitleRows = rangeToRepeat;
}
What the user wants is that each logical block of data be kept together on a sheet, so that a block (5 rows) does not span more than one sheet. IOW, if there are less than 5 rows of space on the current page when a block begins, skip to the next page with a page break.
Is this possible with PivotTables?
I understand the that when you are referring to "logical blocks of data" it means data corresponding to a PivotFieldItem. If that is the case the try this:
Set these PivotTable properties to TRUE:
ActiveSheet.PivotTables("PivotTable1").PrintTitles = True
ActiveSheet.PivotTables("PivotTable1").RepeatItemsOnEachPrintedPage = True
Also set to TRUE the LayoutPageBreak property of the PivotField for which you want to set a page break every time there is a change of item:
ActiveSheet.PivotTables("PivotTable1").PivotFields("Class").LayoutPageBreak = True
Also need to set this property to TRUE in case there are items with only one record.
ActiveSheet.PivotTables("PivotTable1").PivotFields("Class").LayoutBlankLine = True
Replace "PivotTable1" and "Class" values as required
Although the commands above are in VBA they should give you a good idea of how to set these properties using C#
I have a datagridview that I want to allow user from resizing columns and prevent hom from resizing rows. I am setting the properties in design and also at runtime but it doesn't affect the datagridview.
The opposite happens, the rows can be resized and the columns not.
I tried to reverse the properties values but same result.
private void SetupAlternatesDataGridView()
{
var recordstateColumn = new DataGridViewTextBoxColumn();
recordstateColumn.Name = Glossary.RecordState;
recordstateColumn.HeaderText = Glossary.RecordStateTitle;
var alternateStatusColumn = new DataGridViewTextBoxColumn();
alternateStatusColumn.Name = Glossary.AliasAlternateStatus;
alternateStatusColumn.HeaderText = Glossary.AlternateStatusTitle;
var alternateNumberColumn = new DataGridViewTextBoxColumn();
alternateNumberColumn.Name = Glossary.AliasAlternateNumber;
alternateNumberColumn.HeaderText = Glossary.AlternateNumberTitle;
AlternateDGV.AllowUserToResizeColumns = true;
AlternateDGV.AllowUserToResizeRows = false;
//TODO: For test only, remove it
AlternateDGV.Columns.AddRange(recordstateColumn, alternateStatusColumn, alternateNumberColumn);
AlternateDGV.Rows.Add("added", "A", "POS-100");
}
How to make those properties work?
Just play with all the properties and found that AutoSizeColumnsMode must be set to None in order to AllowUserToResizeColumns and AllowUserToResizeRows to work.
AutoSizeColumnsMode = None
In my case, it didn't work because I had this line:
Grid.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
In other words, if you ask one column to fill all available space, the user won't be able to resize it (at least on Windows 10).
But if your entire grid is set to "Fill", like this:
Grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
then resizing will be allowed.
I want to display a simple nsoutlineview that will display a hierarchy.
When I did it via InterfaceBuilder, everything was fine, but now that I'm trying to it programmatically, I have some trouble.
Here the code I use to display the outline view, inside a nsscrollview :
this.OutlineView = new NSOutlineView();
this.OutlineView.IndentationPerLevel = 16.0f;
this.OutlineView.IndentationMarkerFollowsCell = true;
this.OutlineView.SelectionHighlightStyle = NSTableViewSelectionHighlightStyle.Regular;
this.OutlineView.HeaderView = null;
this.OutlineView.BackgroundColor = NSColor.FromDeviceRgba(225f/255f,228f/255f,232f/255f,1f);
this.OutlineView.DataSource = dataSource;
this.OutlineView.Delegate = aDelegate;
NSTableColumn tableColumn = new NSTableColumn("Name");
tableColumn.Editable = false;
tableColumn.MinWidth = 100f;
this.OutlineView.AddColumn(tableColumn);
this.DocumentView = this.OutlineView;
And this is what I get when I want to display the hierarchy of a root directory and a file inside this directory :
No arrow before root, no indentation of the file in the directory...
Ok found it after looking in the debugger how xCode construct the scroll view :S
In addition to adding the table column, you have to set the OutlineTableColumn, by adding this line :
this.OutlineView.OutlineTableColumn = tableColumn;
In DevExpress XtraGrid an Empty Bands is displayed when one of its column position is set Fixed.
Here is the code:
gridview1.DataSource = ds.Table[0];
gridview1.OptionsView.ColumnAutoWidth = false;
gridview1.PopulateColumns();
GridBand DateGridBand = new GridBand();
DateGridBand.Columns.Add(gridview1.Columns["Date"]);
gridview1.Bands.Add(DateGridBand).Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Left;
GridBand gdBand = new GridBand();
gdBand .Caption = "Details";
gdBand .Columns.Add(gridview1.Columns["No"]);
gdBand .Columns.Add(gridview1.Columns["Qty");
gridview1.Bands.Add(gdBand );
how to avoid the Blank Bands.
Thanks.
You need to remove the header row.
// remove header row
GridView1.OptionsView.ShowColumnHeaders = False;
Knowing the two below will save you some time with further customization.
// remove side indicator
GridView1.OptionsView.ShowIndicator = False;
// remove group header
GridView1.OptionsView.ShowGroupPanel = False;
In my application, I have a DataGridView that moves from one Tab Control to another Tab Control.
I am doing this by changing its parent. This works with no problems on the first move from the origional Tab Control to the new one, but when changing the parent back to the origional, the DataGridView shows up (all the Columns are visible) but there is no data in the view.
I have tried to reload the data into the DataGridView, and refresh/Invalidate the control to make it redraw, but it still shows up empty. However, when the control goes back to the secondary parent, the data is back.
I am also using this exact code for another DataGridView and it works without any problems at all.
Any ideas would be greatly appreciated, and thanks in advance.
From Origional to Secondary
gvwRFIs.Parent = tabProcessingRFI; //Working
gvwConsentInfoMemos.Parent = tabProcessingMemos; //Working
From Secondary to Origional
gvwRFIs.Parent = tabConsentInfoRFI; //Empty Data
gvwConsentInfoMemos.Parent = tabConsentInfoMemos; //Working
RFI DataGridView Designer Code
//
// gvwRFIs
//
this.gvwRFIs.AllowUserToAddRows = false;
this.gvwRFIs.AllowUserToDeleteRows = false;
this.gvwRFIs.AllowUserToResizeRows = false;
this.gvwRFIs.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders;
this.gvwRFIs.BackgroundColor = System.Drawing.Color.White;
this.gvwRFIs.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.gvwRFIs.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.gvwID,
this.gvwType,
this.gvwSeq,
this.gvwCreated,
this.gvwProcessor,
this.gvwLetter,
this.gvwResponded,
this.gvwS,
this.gvwDetails});
this.gvwRFIs.Dock = System.Windows.Forms.DockStyle.Fill;
this.gvwRFIs.Location = new System.Drawing.Point(3, 3);
this.gvwRFIs.MultiSelect = false;
this.gvwRFIs.Name = "gvwRFIs";
this.gvwRFIs.ReadOnly = true;
this.gvwRFIs.RowHeadersVisible = false;
this.gvwRFIs.RowHeadersWidth = 4;
this.gvwRFIs.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.gvwRFIs.Size = new System.Drawing.Size(1078, 422);
this.gvwRFIs.TabIndex = 4;
this.gvwRFIs.DoubleClick += new System.EventHandler(this.gvwRFIs_DoubleClick);
Consent Tab Control Designer Code
//
// tabConsentInfoRFI
//
this.tabConsentInfoRFI.Controls.Add(this.gvwRFIs);
this.tabConsentInfoRFI.Controls.Add(this.lvwConsentInfoRFI);
this.tabConsentInfoRFI.Location = new System.Drawing.Point(4, 32);
this.tabConsentInfoRFI.Name = "tabConsentInfoRFI";
this.tabConsentInfoRFI.Padding = new System.Windows.Forms.Padding(3);
this.tabConsentInfoRFI.Size = new System.Drawing.Size(1084, 428);
this.tabConsentInfoRFI.TabIndex = 4;
this.tabConsentInfoRFI.Text = "RFI\'s";
this.tabConsentInfoRFI.UseVisualStyleBackColor = true;
Processing Tab Control Designer Code
//
// tabProcessingRFI
//
this.tabProcessingRFI.Location = new System.Drawing.Point(4, 36);
this.tabProcessingRFI.Name = "tabProcessingRFI";
this.tabProcessingRFI.Padding = new System.Windows.Forms.Padding(3);
this.tabProcessingRFI.Size = new System.Drawing.Size(868, 465);
this.tabProcessingRFI.TabIndex = 1;
this.tabProcessingRFI.Text = "RFI";
this.tabProcessingRFI.UseVisualStyleBackColor = true;
I found the issue,
The ListView that is in the consent designer code, is an old control that looks identical, but is no longer used. So when the control is parented back to the Origional tab, it is in the background of this control.
Once the control was removed (thought it already was) the code worked perfectly.
Thank you to LarsTech for getting me in the right direction. And akhisp for there answer.
You should remove the object from the Tab.Controls list of the tab that it's no longer in. So do something like:
tabProcessingRFI.Controls.Remove(gvwRFIs);
gvwRFIs.Parent = tabConsentInfoRFI