我有一个.xlsx格式的Excel文件.我通过合并单元格来形成各种列来存储数据.我正在通过Java Web应用程序读取Excel文件并将其数据保存到数据库(MySQL).但是当我从合并的单元格中读取时,我得到的是空值以及存储在列和标题中的内容.我正在使用Apache POI.我的代码是:
public static void excelToDBLogIN() {
FileInputStream file = null;
Boolean flag = true;
ArrayList<String> rows = new ArrayList<String>();
try {
// here uploadFolder contains the path to the Login 3.xlsx file
file = new FileInputStream(new File(uploadFolder + "Login 3.xlsx"));
//Create Workbook instance holding reference to .xlsx file
XSSFWorkbook workbook = new XSSFWorkbook(file);
//Get first/desired sheet from the workbook
XSSFSheet sheet = workbook.getSheetAt(0);
//Iterate through each rows one by one
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext()) {
Row …Run Code Online (Sandbox Code Playgroud) 在XLSX文件(Excel 2007)中的工作表的XML中,具有等于"s"的"t"属性的单元格标签是字符串类型.需要通过sharedStrings文档查找并转换c中的value标记.但是,有些单元格的s ="237"并且根本没有t属性.value标签有一个像39448这样的整数,它与sharedStrings文档无关.Excel中显示的值是日期1/1/2008.
s属性在XLSX中的ac标记中表示什么?
未知的价值
<c r="B47" s="237">
<v>39448</v>
</c>
Run Code Online (Sandbox Code Playgroud)
共享字符串值
<c r="C47" t="s">
<v>7</v>
</c>
Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个应用程序,它在tableview中显示一些推文.在故事板上我创建了一个原型单元格,其中包括推文条目的基本gui概念.
看起来大概是这样的:
++++++++++++++
++Username++++
++++++++++++++
++Tweet+++++++
++++++++++++++
++Time-Ago++++
++++++++++++++
Run Code Online (Sandbox Code Playgroud)
现在我用以下代码计算单元格的高度,但不知怎的,它失败了.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary * currentTweet = [tweetArray objectAtIndex: indexPath.row];
NSString * tweetTextString = [currentTweet objectForKey: @"text"];
CGSize textSize = [tweetTextString sizeWithFont:[UIFont systemFontOfSize:15.0f] constrainedToSize:CGSizeMake(630, 1000) lineBreakMode: NSLineBreakByWordWrapping];
float heightToAdd = 24 + textSize.height + 15 + 45;
if(heightToAdd < 90) {
heightToAdd = 90;
}
return heightToAdd;
}
Run Code Online (Sandbox Code Playgroud)
顺便说一下,还有其他的东西,这很奇怪.如果我滚动tableview整个应用程序似乎冻结.这是正常的还是我做错了什么?
我有一个网站,用户上传照片和创建相册.此外,他们可以在绝对位置,旋转和对齐方式添加文本.文本可以有新行.
我一直在使用Itext Library来自动创建后来打印的Photobooks高质量Pdfs.
将用户上传的图像添加到PDF非常简单,当我尝试添加文本时出现问题.
理论上我需要做的是定义一个定义宽度和高度的段落,设置用户文本,字体,字体样式,对齐(中心,左,右,对齐),最后设置旋转.
对于我读过的关于Itext的内容,我可以创建一个设置用户属性的段落,并使用ColumnText对象来设置绝对位置,宽度和高度.但是,不可能将任何大于单线的旋转设置为旋转.
我也不能使用表格单元格,因为旋转方法只允许90度的倍数.
有没有办法添加一个旋转(如20度)的段落,而不必使用该ColumnText.showTextAligned()方法逐行添加文本和涉及的所有数学?
----编辑:08-Ago-2013 ----
如果它可以帮助任何人,这是我用来解决这个问题的代码(感谢Bruno):
//Create the template that will contain the text
PdfContentByte canvas = pdfWriter.getDirectContent();
PdfTemplate textTemplate = canvas.createTemplate(imgWidth, imgHeight); //The width and height of the text to be inserted
ColumnText columnText = new ColumnText(textTemplate);
columnText.setSimpleColumn(0, 0, imgWidth, imgHeight);
columnText.addElement(paragraph);
columnText.go();
//Create de image wraper for the template
Image textImg = Image.getInstance(textTemplate);
//Asign the dimentions of the image, in this case, the text
textImg.setInterpolation(true);
textImg.scaleAbsolute(imgWidth, imgHeight);
textImg.setRotationDegrees((float) -textComp.getRotation()); //Arbitrary number …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用xlrd读取Excel的合并单元格.
我的Excel :(请注意,第一列合并在三行中)
A B C
+---+---+----+
1 | 2 | 0 | 30 |
+ +---+----+
2 | | 1 | 20 |
+ +---+----+
3 | | 5 | 52 |
+---+---+----+
Run Code Online (Sandbox Code Playgroud)
我想在这个例子中读取第一列的第三行等于2,但它返回''.你知道如何获得合并单元格的价值吗?
我的代码:
all_data = [[]]
excel = xlrd.open_workbook(excel_dir+ excel_file)
sheet_0 = excel.sheet_by_index(0) # Open the first tab
for row_index in range(sheet_0.nrows):
row= ""
for col_index in range(sheet_0.ncols):
value = sheet_0.cell(rowx=row_index,colx=col_index).value
row += "{0} ".format(value)
split_row = row.split()
all_data.append(split_row)
Run Code Online (Sandbox Code Playgroud)
我得到了什么:
'2', '0', '30'
'1', '20' …Run Code Online (Sandbox Code Playgroud) 我能够将整个笔记本导出为HTML,但我想只导出一个单元格及其输出.
有没有办法做到这一点?
我会有另外两种颜色的行,如第一个黑色,第二个白色,第三个黑色等等......
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
cell = ((MainCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]);
if (cell==nil) {
NSArray *topLevelObjects=[[NSBundle mainBundle] loadNibNamed:@"MainCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
if ((indexPath.row % 2)==0) {
[cell.contentView setBackgroundColor:[UIColor purpleColor]];
}else{
[cell.contentView setBackgroundColor:[UIColor whiteColor]];
}
cell = (MainCell *) currentObject;
break;
}
}
}else {
AsyncImageView* oldImage = (AsyncImageView*)
[cell.contentView viewWithTag:999];
[oldImage removeFromSuperview];
}return cell;
Run Code Online (Sandbox Code Playgroud)
问题是,当我进行快速滚动时,细胞的背景变得像最后2个细胞黑色,前2个细胞白色或类似的东西,但如果我滚动慢工作正常.我认为问题是reusableCell的缓存.
有任何想法吗?
TIA
我正在尝试获取有关我的手机可以"看到"atm的相邻单元格的信息.到现在为止还挺好.我是这样做的:
telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//...
ArrayList<NeighboringCellInfo> neighboringCellList = (ArrayList<NeighboringCellInfo>) telManager.getNeighboringCellInfo();
Run Code Online (Sandbox Code Playgroud)
不幸的是,这个名单一直都是空的.即使在不同的地方.我住在柏林,所以我不认为这是因为实际上只有一个单元可用!
更新:我的权限如下所示:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Run Code Online (Sandbox Code Playgroud) 我有问题在每个单元格中设置不同的格式,我想将数字格式设置为千位分隔符和千位分隔符与3位小数,当数字不是整数时,这是我的代码,我认为问题看起来像每个单元格格式由最后fomat设置设置为循环
所以输出应该像这12345 - > 12 345; 425 - > 425; 41,2 - > 41,2; 4578,25 - > 4 578,25
short doubleFormat = hssfOutputWorkBook.CreateDataFormat().GetFormat("#,##0.###");
short intFormat = hssfOutputWorkBook.CreateDataFormat().GetFormat("#,##0");
for (i = 0; i <= unorderedSheet.LastRowNum; i++)
{
NPOI.SS.UserModel.IRow newRow = orderedSheet.CreateRow(i);
NPOI.SS.UserModel.IRow oldRow = unorderedSheet.GetRow(i);
if (oldRow != null)
{
foreach (ICell oldCell in oldRow.Cells)
{
ICell newCell = newRow.CreateCell(mapping[n]);
switch (oldCell.CellType)
{
case CellType.NUMERIC:
newCell.SetCellType(CellType.NUMERIC);
newCell.SetCellValue(oldCell.NumericCellValue);
if (numberHasDecimals(oldCell.NumericCellValue))
{
newCell.CellStyle.DataFormat = doubleFormat;
}
else
{
newCell.CellStyle.DataFormat = intFormat;
}
break; …Run Code Online (Sandbox Code Playgroud) 我在互联网上搜索了很多解决这个问题的方法,但我无法弄明白.我正在尝试在表格视图中创建自定义单元格.
我创建了一个CustomCell.swift类来配置我想要的自定义单元格中的标签,通过storyboard(tableview中的第一个原型单元格)创建它,并将其与标识符链接到cellForRowAtIndexPath方法
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cellIdentifier = "huisCell"
var cell: CustomCell? = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? CustomCell
if cell == nil {
cell = CustomCell(style: UITableViewCellStyle.Value1, reuseIdentifier: cellIdentifier)
}
cell!.huisAdresLabel.text = "123"
cell!.huisDetailLabel.text = "456"
return cell
}
Run Code Online (Sandbox Code Playgroud)
我的CustomCell.swift代码是这样的:
class CustomCell: UITableViewCell {
@IBOutlet var huisAdresLabel: UILabel
@IBOutlet var huisDetailLabel: UILabel
}
Run Code Online (Sandbox Code Playgroud)
它现在非常基本,但我只是希望它能够工作,因为我可以扩展具有更多属性的单元格并更好地设计样式.
通过DropBox的图片因为我需要10个声誉来正确记录我的问题:)
https://www.dropbox.com/sh/5v9jb6cqp80knze/AAD5-yPR8-KoStQddkqKIbcUa
我希望有人可以解释我做错了什么.
编辑:
为了清理一些东西,在我尝试制作一个自定义单元格之前,我让它使用基本单元格,左侧有一个标签.但是当我尝试设置tableview样式并创建自定义单元格时,它将无法工作.
此外,在测试不同的解决方案时,我遇到了CustomCell.swift中的两个标签为零的问题.即使我做了一个自定义init并且做了一个
self.huisAdresLabel = UILabel()
Run Code Online (Sandbox Code Playgroud)
它仍然是零.在我向您展示的代码中,它打印出以下内容:
<UILabel: 0xb2aadc0; frame = (0 -21; 42 21); text = '123'; …Run Code Online (Sandbox Code Playgroud) cell ×10
ios ×2
uitableview ×2
android ×1
apache ×1
apache-poi ×1
c# ×1
cocoa-touch ×1
excel ×1
export ×1
format ×1
gsm ×1
ipad ×1
ipython ×1
itext ×1
java ×1
jupyter ×1
npoi ×1
objective-c ×1
paragraph ×1
python ×1
rotation ×1
storyboard ×1
swift ×1
tableview ×1
tags ×1
xcode6 ×1
xlrd ×1
xlsx ×1
xml ×1