使用我的EPPlus代码创建的电子表格的“打印预览”显示了装订线/行号列(可以这么说第0列):
如何以编程方式防止印刷品中的装订线/行号(“裂缝?”)列?
我的打印设置代码目前如下:
private void ConfigureCustomerSheetForPrinting()
{
string columnName = GetExcelTextColumnName(customerWorksheet.Dimension.End.Column);
string printArea = string.Format("A1:{0}{1}", columnName, customerWorksheet.Dimension.End.Row);
customerWorksheet.PrinterSettings.PrintArea = customerWorksheet.Cells[printArea];
customerWorksheet.PrinterSettings.FitToPage = true;
customerWorksheet.PrinterSettings.Orientation = eOrientation.Landscape;
customerWorksheet.View.ZoomScale = 100;
customerWorksheet.PrinterSettings.FitToPage = true;
customerWorksheet.PrinterSettings.FitToHeight = 100;
customerWorksheet.PrinterSettings.Scale = 100;
customerWorksheet.PrinterSettings.LeftMargin = (decimal).5 / 2.54M;
customerWorksheet.PrinterSettings.RightMargin = (decimal).5 / 2.54M;
customerWorksheet.PrinterSettings.TopMargin = (decimal).5 / 2.54M;
customerWorksheet.PrinterSettings.BottomMargin = (decimal).5 / 2.54M;
customerWorksheet.PrinterSettings.HeaderMargin = (decimal).5 / 2.54M;
customerWorksheet.PrinterSettings.FooterMargin = (decimal).5 / 2.54M;
}
答案 0 :(得分:1)
如果我理解你的要求,你想要显示列标题(比如说“行0”,“B”,“C”,......),但不显示行标题(说“第0列“为”1“,”2“3”等。如果是这样,我从未见过如何做到这一点。你可以隐藏行/列标题或显示两者但不是 - 或根据DocumentFormat.OpenXml.Spreadsheet.PrintOptions。基本上是您和Richardo谈到的ShowHeaders
选项。
我能想到的唯一体面的工作就是用这样的东西来伪造它。这包括将第一行设置为重复。我将第一行设置为冻结,但这是可选的:
using (var pck = new ExcelPackage(fi))
{
var wb = pck.Workbook;
var ws = wb.Worksheets.Add("Sheet1");
//Make sure headers are not show
ws.PrinterSettings.ShowHeaders = false;
//Header
ws.Cells[1, 1].Value = "A";
ws.Cells[1, 2].Value = "B";
ws.Cells[1, 3].Value = "C";
ws.Cells[1, 4].Value = "D";
var headerrange = ws.Cells[1, 1, 1, 4];
headerrange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
headerrange.Style.Border.Top.Style = ExcelBorderStyle.Thin;
headerrange.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
headerrange.Style.Border.Left.Style = ExcelBorderStyle.Thin;
headerrange.Style.Border.Right.Style = ExcelBorderStyle.Thin;
ws.View.FreezePanes(1,4);
ws.PrinterSettings.RepeatRows = new ExcelAddress("$1:$1");
//Some data > 1 page
for (var i = 0; i < 1000; i++)
{
ws.Cells[2 + i, 1].Value = DateTime.Now.AddDays(i);
ws.Cells[2 + i, 2].Value = i;
ws.Cells[2 + i, 3].Value = i*100;
ws.Cells[2 + i, 4].Value = Path.GetRandomFileName();
}
//Save it
pck.Save();
}
在输出中给出了这个:
这在打印预览中(我向下滚动了几页):
答案 1 :(得分:0)
PrinterSettings对象中有一个名为public class CustomAdapter extends BaseAdapter {
private ArrayList songList;
private LayoutInflater layoutInflater;
public boolean isVisible;
public CustomAdapter(Context context, ArrayList songList){
this.songList = songList;
layoutInflater = LayoutInflater.from(context);
}
public boolean isVisible(){
return isVisible;
}
public void setIsVisible(boolean isVisible){
this.isVisible = isVisible;
}
@Override
public int getCount() {
return songList.size();
}
@Override
public Object getItem(int position) {
return songList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null){
convertView = layoutInflater.inflate(R.layout.layout_list_row, null);
holder = new ViewHolder();
holder.backgroundImage = (ImageView) convertView.findViewById(R.id.backgroundImage);
holder.topText = (TextView) convertView.findViewById(R.id.topText);
holder.bottomText = (TextView) convertView.findViewById(R.id.bottomText);
holder.button_repeat = (ImageButton) convertView.findViewById(R.id.button_repeat);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
SongItem songItem = (SongItem) songList.get(position);
holder.topText.setText(songItem.getTopText());
holder.bottomText.setText(songItem.getBottomText());
holder.backgroundImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (holder.button_repeat.getVisibility() == View.VISIBLE)
holder.button_repeat.setVisibility(View.GONE);
else holder.button_repeat.setVisibility(View.VISIBLE);
}
});
return convertView;
}
static class ViewHolder {
ImageView backgroundImage;
TextView topText;
TextView bottomText;
ImageButton button_repeat;
}
}
的属性,可以满足您的需要。你似乎没有它,所以你可能会错过它。
ShowHeaders
customerWorksheet.PrinterSettings.ShowHeaders = false;
您可以在customerWorksheet.View.ShowHeaders = false;
类的source code中更明确地看到这一点。
ExcelPrinterSettings
希望它有助于B.;)