I'm trying to execute the following LabTalk script in Origin:
for(ii=1; ii<=4; ii++)
{
string iiString$ = $(ii)
newbook name:="iiString" sheet:=1 option:=lsname
}
I just paste it into Script Window and hit "enter" on my keyboard and nothing happens. I tried also putting a semicolon after:
first row; all text rows; rows in the loop; any of rows.
I also tried version with intended rows that are inside the loop. What may be the problem?
Your syntax for calling the string variable is not correct. If you use iiString$ instead of "iiString" it works fine:
for(int ii=1; ii<=4; ii++)
{
string iiString$ = $(ii)
newbook name:=iiString$ sheet:=1 option:=lsname
}
Related
I'm running into strange problem with .Net version of POI library for Excel Spreadsheets. I'm rewriting from text files to Excel 97-2003 documents and I'm like to add some formatting programmatically depend on some values gather at the begging of the program.
At the beginning, in the same method where I was creating a new cell from given value I was creating also a new Workbook CellStyle which was wrong, because I was running out of the styles very quickly (or I was just thought it was the cause of the problem).
Constructor of the class responsible for Excel Workbook:
public OldExcelWriter(TextWriter logger) : base(logger)
{
_workbook = new HSSFWorkbook();
_sheetData = _workbook.CreateSheet("sheet1");
_creationHelper = _workbook.GetCreationHelper();
}
Method that is calling all the chains of operations:
public void Write(string path, Data data)
{
FillSpreadSheetWithData(data, _sheetData);
SaveSpreadSheet(_workbook, path);
}
Long story short, in FillSpreadSheetWithData I have method for creating a row inside which I'm have a loop for each cell, so basically I'm iterating thru every column, passing IRow references to a row, column value, index and formatting information like this:
for (int j = 0; j < column.Count; j++)
{
CreateCell(row, column[j], j, data.Formatting[j]);
}
and while creating a new styles (for first shot I was trying to pass some date time values) I had situation like this in my rewrited Excel: screenshot of excel workbook
So formatting was passed correctly (also Horizontal Aligment etc.) but it get ugly after 15th row (always the same amount).
DateTime dataCell = DateTime.MaxValue;
var cell = row.CreateCell(columnIndex);
_cellStyle = _workbook.CreateCellStyle();
switch (format.Type)
{
case DataType.Date:
_cellStyle.DataFormat = _creationHelper.CreateDataFormat().GetFormat("m/dd/yyyy");
if (value.Replace("\n", "") != string.Empty)
{
dataCell = DateTime.ParseExact(value.Replace("\n", ""), "m/dd/yyyy",
System.Globalization.CultureInfo.InvariantCulture);
}
break;
}
switch (format.HorizontalAlignment)
{
case Enums.HorizontalAlignment.Left:
_cellStyle.Alignment = HorizontalAlignment.LEFT;
break;
case Enums.HorizontalAlignment.Center:
_cellStyle.Alignment = HorizontalAlignment.CENTER;
break;
}
if (dataCell != DateTime.MaxValue)
{
cell.CellStyle = _cellStyle;
cell.SetCellValue(dataCell);
dataCell = DateTime.MaxValue;
}
else
{
cell.CellStyle = _cellStyle;
cell.SetCellValue(value);
}
(It's not the cleanest code but I will don refactor after getting this work).
After running into this issue I thought that maybe I will create _cellStyle variable in the constructor and only change it's value depends on the case, because it's assigned to the new cell anyway and I see while debugging that object values are correct.
But after creating everything, it won't get any better. Styles was override by the last value of the style, and dates are spoiled also, but later: screnshoot of excel workbook after creating one instance of cell style
I'm running out of ideas, maybe I should create every combination of the cell styles (I'm using only few data formats and alignments) but before I will do that (because I'm running out of easy options right now) I wonder what you guys think that should be done here.
cell format is set to custom with date type
I am using this code to create my custom style and format. Its for XSSF Format of excel sheet. but it will work for HSSF format with some modification.
XSSFFont defaultFont = (XSSFFont)workbook.CreateFont();
defaultFont.FontHeightInPoints = (short)10;
defaultFont.FontName = "Arial";
defaultFont.Color = IndexedColors.Black.Index;
defaultFont.IsBold = false;
defaultFont.IsItalic = false;
XSSFCellStyle dateCellStyle = (XSSFCellStyle)workbook.CreateCellStyle();
XSSFDataFormat dateDataFormat = (XSSFDataFormat)workbook.CreateDataFormat();
dateCellStyle.SetDataFormat(dateDataFormat.GetFormat("m/d/yy h:mm")); //Replace format by m/dd/yyyy. try similar approach for phone number etc.
dateCellStyle.FillBackgroundColor = IndexedColors.LightYellow.Index;
//dateCellStyle.FillPattern = FillPattern.NoFill;
dateCellStyle.FillForegroundColor = IndexedColors.LightTurquoise.Index;
dateCellStyle.FillPattern = FillPattern.SolidForeground;
dateCellStyle.Alignment = HorizontalAlignment.Left;
dateCellStyle.VerticalAlignment = VerticalAlignment.Top;
dateCellStyle.BorderBottom = BorderStyle.Thin;
dateCellStyle.BorderTop = BorderStyle.Thin;
dateCellStyle.BorderLeft = BorderStyle.Thin;
dateCellStyle.BorderRight = BorderStyle.Thin;
dateCellStyle.SetFont(defaultFont);
//Apply your style to column
_sheetData.SetDefaultColumnStyle(columnIndex, dateCellStyle);
// Or you can also apply style cell wise like
var row = _sheetData.CreateRow(0);
for (int cellIndex = 0;cellIndex < TotalHeaderCount;cellIndex++)
{
row.Cells[cellIndex].CellStyle = dateCellStyle;
}
I'm making like a "mini programming language" in visual basic.
Mostly just for practice and for fun.
I just have one problem. I want to make a commenting system.
I got an idea how it would work, but i don't know how to do it.
So this is what i want to do:
I want to start to select all text from //
So for example, if i write:
print = "Hello World!"; //This is a comment!
it will select everything from the // so it will select
//This is a comment!
Then i would just replace the selected text with nothing.
You can use String.IndexOf + Substring:
Dim code = "Dim print = ""Hello World!""; //This is a comment!"
Dim indexOfComment = code.IndexOf("//")
Dim comment As String = Nothing
If indexOfComment >= 0 Then comment = code.Substring(indexOfComment)
If you want the part before the comment dont use String.Replace but also Substring or Remove:
code.Substring(0, indexOfComment)
i have some problem with changing value in QTableView cell.
ui->search_results->show();
int num = model->rowCount();
for (int i = 0; i<num; i++) {
QSqlRecord rec = model->record(i);
QString file_chron = rec.value(1).toString();
QString file_age = get_file_agestring_from_chron(file_chron);
//model->setData(model->index(i,1), QVariant(file_age), Qt::EditRole);
rec.setValue(1,file_age);
it seems that both functions work as they should in a loop
qDebug()<<rec.value(1).toString()+" "+rec.value(2).toString()+" "+rec.value(3).toString()+" "+rec.value(4).toString()+" "+rec.value(5).toString();
}
but outside we have old value.
qDebug()<<model->data(model->index(3,1)).toString();
ui->search_results->setModel(model);
ui->search_results->hideColumn(4);
i need to reimplement value inside this field.
I think that it is access error, but i can't understand how to set new value!
sorry, i can't add tag QSqlQueryModel
You are operation on QSqlRecord rec; which is copy of the record instead of the reference to it. As for setting data - see model : setData function
The code below is action taken when a button is clicked on a simple form. The problem comes with the one if/else block. The If line is not terminated. The Else line is not terminated. But I have a consistent error that my Else exists without an If. I can't see why. I need someone smarter than me to identify what is going on here.
Thank you in advance!
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
FileFilter filter;
filter = new FileNameExtensionFilter("Comma Separated Value files","csv","txt");
JFileChooser chooser;
chooser = new JFileChooser();
chooser.addChoosableFileFilter(filter);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int showDialog = chooser.showDialog(this, null);
File selectedFile = chooser.getSelectedFile();
String filename;
filename = selectedFile.getAbsolutePath();
if (filter.accept(selectedFile))
{
jTextField2.setText(filename);
jTextField2.setBackground(Color.white);
else
jTextField2.setText("You Did NOT Select a CSV File.");
jTextField2.setForeground(Color.black);
jTextField2.setBackground(Color.red);
}
}
You are missing the bracket '}' after "jTextField2.setBackground(Color.white);" and else.code is here
if (filter.accept(selectedFile))
{
jTextField2.setText(filename);
jTextField2.setBackground(Color.white);
}
else
{
jTextField2.setText("You Did NOT Select a CSV File.");
jTextField2.setForeground(Color.black);
jTextField2.setBackground(Color.red);
}
The SYNTAX for if-else Block looks like this:-
if {
// statements
} else {
//statements
}
Now if you are having only ONE statement inside the if Or else part then you can afford to skip the curly braces{ } otherwise you surely need to put those curly braces as compiler looks for it can terminate the execution of if statement.
However, it is always recommended to use the braces even if u have only ONE statement inside the if or else part as it improves the readability of the code.
You need to close your "if" and "else" blocks.
Example: if {} else {}.
if (filter.accept(selectedFile)) {
jTextField2.setText(filename);
jTextField2.setBackground(Color.white);
} else {
jTextField2.setText("You Did NOT Select a CSV File.");
jTextField2.setForeground(Color.black);
jTextField2.setBackground(Color.red);
}
The if's closing bracket is missing just before the else.
How can I find the end position of enumerator? For this enumerator I didn't see any atEnd method in the documentation.
SortedSet<Button ^>::Enumerator^ enumer = btnSet->GetEnumerator();
enumer->atEnd();
my error
error 'atEnd' : is not a member of 'System::Collections::Generic::SortedSet<T>::Enumerator'
Is your intention to write a loop like while (enumer != btnSet->end()), as is common with many C++ iterators?
You can check if an enumerator is not yet at the end, by checking the return value of MoveNext(), so the loop would be this:
SortedSet<Button^>::Enumerator^ enumer = btnSet->GetEnumerator();
while (enumer->MoveNext()) {
Button^ btn = enumer->Current;
// do stuff
}
You could also iterate over the collection using a for each loop, which looks a bit cleaner:
for each (Button^ btn in btnSet) {
// do stuff
}