I have already this code
Excel::_ApplicationPtr app("Excel.Application");
app->Visible[0] = false;
Excel::_WorkbookPtr book = app->Workbooks->Add();
Excel::_WorksheetPtr sheet = book->Worksheets->Item[1];
RangePtr pRange = sheet->Cells;
RangePtr pCell;
pCell = pRange->Item[1][1]; // A1
pCell->Value2 = "1";
pCell = pRange->Item[1][2]; // B1
pCell->Value2 = "1";
pCell = pRange->Item[1][3]; // C1
pCell->Value2 = "10";
pCell = pRange->Item[2][1]; // A2
pCell->Value2 = "3";
pCell = pRange->Item[2][2]; // B2
Cell->Value2 = "1";
pCell = pRange->Item[2][3]; // C2
pCell->Value2 = "20";
and next
Excel::RangePtr pBeginRange = pRange->Item[1][1];
Excel::RangePtr pEndRange = pRange->Item[5][9];
Excel::RangePtr pTotalRange = sheet->Range[(Excel::Range *)pBeginRange][(Excel::Range *)pEndRange];
_ChartPtr pChart2 = book->Charts->Add();
pChart2->ChartType = xlBubble3DEffect;
pChart2->SetSourceData((Excel::Range *)pTotalRange, (long)Excel::xlColumns);
How to disable automatic creation SeriesCollection in Excel Chart. I want to set the ranges manually. In the automatic creation all SeriesCollection has XValues in the first column. But I needn't it.
I've come across the same issue as well. From experimentation I think the following is happening:
When you create a new chart in VBA using the following code
Dim chSheet As Chart
Set chSheet = Charts.Add
Excel, trying to be helpful I bet, automatically looks at which ever worksheet your cursor had selected when you executed your code from the developer window and searches for the nearest dataset it thinks could be a range of values for the graph. This is then automatically populated in the graph. The only way around it I've found so far is to execute the following code to delete all series objects in the series collection object on the chart immediately after having created it. Touch counter intuitive but it works...
Public Sub DeleteChartSeries(chartSheet As Chart)
'Shorter but perhaps less clean way of writing the code compared to below
Do Until chartSheet.SeriesCollection.Count = 0
chartSheet.SeriesCollection(1).Delete
Loop
'With chartSheet
' Do Until .seriesCollection.Count = 0
' .seriesCollection(1).Delete
' Loop
'End With
End Sub
Just hit a workaround: First move the cursor somewhere outside the UsedRange, then create the Chart: Won't do auto-detection. Then move back.
In other words, the following code works for me (Excel 2007):
' Assume src As Range (proposed source data for the chart) in the ActiveSheet.
' put the cursor somewhere outside the UsedRange to avoid Excel's
' 'helpful' auto detection.
Dim ur As Range
Set ur = src.Worksheet.UsedRange
ur.Cells(1, ur.Columns.Count).Offset(0, 2).Select
Dim crt As Chart
Set crt = src.Worksheet.Shapes.AddChart().Chart
' ^ does NOT do auto-detection.
Probably can't prevent it being created, but you can delete it immediately after creating the chart, then create you own series as required.
In VBA:
Set Chrt = wb.Charts.Add()
Chrt.SeriesCollection(1).Delete
Related
I ve been getting some issues trying to use IF statement using items on the sheets as answers, mostly i been trying either using as firt statement a string directly or using another cell of the sheets with the statement comparing to the one i ve been trying to detect with out any results. Mostly my objective would be to, with a daly trigger, use an IF statement to detect every day if the date of today is the same as a date marked on a cell, my only current solution is and only thing is to make it detect if a cell is empty or not, so i just been using google Formulas that do the detect of the date, and if True make it empty, and if not make something appear
Here are some of the tests I ve been trying
Test 1:
var Sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SheetName");
else if (Sheet.getRange(1, 1).getValue() == "2/2/2020"){}
(cell A1=2/2/2020)
Test 2:
var Sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SheetName");
else if (Sheet.getRange(1, 1).getValue() == Sheet.getRange(1, 2).getValue()){}
(cell A1=2/2/2020)
(cell B1=2/2/2020)
Here are two solutions depending on what you are trying to accomplish.
This first one gets the values, formats them to a date format, and then compares them
function myFunction() {
var tz = Session.getScriptTimeZone();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('SheetName');
var data = sheet.getDataRange().getValues();
var aVal = Utilities.formatDate(data[0][0],tz,'MM/dd/YYYY');
var bVal = Utilities.formatDate(data[0][1],tz,'MM/dd/YYYY');
Logger.log([aVal,bVal])
if(aVal == bVal) {
//do something
}
}
This second section gets the display values and compares them. The first solution compares the date values while this second solution compares the dates as a string. Good luck!
function myFunction1() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('SheetName');
var data = sheet.getDataRange().getDisplayValues();
var aVal = data[0][0]
var bVal = data[0][1]
Logger.log([aVal,bVal])
if(aVal == bVal) {
//do something
}
}
I used to use below code to load plenty of text to VCL Memo.
LogMemo->Lines->BeginUpdate();
LogMemo->SelStart = LogMemo->GetTextLen();
LogMemo->SelLength = 0;
LogMemo->SelText = AnsiString((char *)LogMemoBufPtr->Memory, LogMemoBufPtr->Size);
LogMemo->SelStart = LogMemo->GetTextLen();
LogMemo->Perform(EM_SCROLLCARET, 0, 0);
LogMemo->Lines->EndUpdate();
But in FMX Memo component, I can't use "LogMemo->SelText = AnsiString(strFromMemStream)" anymore.
And I also can't use "GetTextLen" method to set selection start.
I tried to modify the code in below but it still didn't work. It always overwrite original content and can't append new text.
LogMemo->Lines->BeginUpdate();
LogMemo->GoToTextEnd();
LogMemo->SelStart = LogMemo->Text.Length();
LogMemo->SelLength = 0;
LogMemo->Text = AnsiString((char *)LogMemoBufPtr->Memory, LogMemoBufPtr->Size);
LogMemo->GoToTextEnd();
LogMemo->SelStart = LogMemo->Text.Length();
LogMemoBufPtr->Clear();
LogMemo->Lines->EndUpdate();
Is there any one know how to do it in FMX Memo component or just to display plenty of text smoothly?
Thanks!
Use the SetText function or Lines property.
In both cases I think you will have to convert the ASCII text to Unicode first.
Solution 1 - Based to the second source code provided, here is a solution to append a text in the TMemo object in FMX/FireMonkey Library.
Step 1 - Instead of trying to place the cursor and select the end of the text.
Before:
LogMemo->GoToTextEnd();
LogMemo->SelStart = LogMemo->Text.Length();
LogMemo->SelLength = 0;
Select all the text and store it in a temporary string.
After:
System::UnicodeString suTemp;
LogMemo->Lines->BeginUpdate();
LogMemo->GoToTextEnd();
LogMemo->SelStart = 0;
LogMemo->SelLength = LogMemo->Text.Length();
suTemp = LogMemo->SelText;
Step 2 - Then append the new text to the temporary string and update the Memo
suTemp += AnsiString((char *)LogMemoBufPtr->Memory, LogMemoBufPtr->Size);
LogMemo->Text = suTemp;
LogMemo->GoToTextEnd();
LogMemo->SelStart = LogMemo->Text.Length();
LogMemoBufPtr->Clear();
LogMemo->Lines->EndUpdate();
Solution 2 - Simple and faster solution when add the text at the end.
Store the current text into a temporary string and add the new text
then update the memo.
System::UnicodeString suTemp;
LogMemo->Lines->BeginUpdate();
suTemp = LogMemo->Text;
suTemp += AnsiString((char *)LogMemoBufPtr->Memory, LogMemoBufPtr->Size);
LogMemo->Text = suTemp;
LogMemo->GoToTextEnd();
LogMemoBufPtr->Clear();
LogMemo->Lines->EndUpdate();
TMemo in FireMonkey has a GoToTextEnd() method:
Moves the cursor to the end of the text in the memo control.
You can't use AnsiString in mobile platforms (without a compiler patch), nor should you anyway since TMemo holds Unicode text (same as VCL's TMemo in Delphi 2009 and later). If your TMemoryStream contains 8bit characters, you need to convert them to Unicode, such as with TEncoding, before appending them to the TMemo. The TEncoding::GetString() methods take a TBytes as input, so you could use TBytesStream instead of TMemoryStream. TBytesStream wraps a TBytes and has a public Bytes property.
Try something like this:
LogMemo->Lines->BeginUpdate();
try
{
LogMemo->GoToTextEnd();
LogMemo->SelLength = 0;
LogMemo->SelText = TEncoding::Default->GetString(LogMemoBufPtr->Bytes, 0, LogMemoBufPtr->Size);
/* or:
TEncoding *enc = TEncoding::GetEncoding(L"desired charset here");
try {
LogMemo->SelText = enc->GetString(LogMemoBufPtr->Bytes, 0, LogMemoBufPtr->Size);
}
__finally {
delete enc;
}
*/
LogMemo->GoToTextEnd();
LogMemo->SelLength = 0;
// not sure if this is the best replacement for EM_SCROLLCARET...
LogMemo->VScrollBar->Value = LogMemo->VScrollBar->Max;
}
__finally {
LogMemo->Lines->EndUpdate();
}
Update: I didn't realize that SelText is read-only in FireMonkey, unlike in VCL. In that case, you have no choice but to append to the Text property, which is not as efficient, especially for large text.
LogMemo->Lines->BeginUpdate();
try
{
LogMemo->Text = LogMemo->Text + TEncoding::Default->GetString(LogMemoBufPtr->Bytes, 0, LogMemoBufPtr->Size);
/* or:
TEncoding *enc = TEncoding::GetEncoding(L"desired charset here");
try {
LogMemo->Text = LogMemo->Text + enc->GetString(LogMemoBufPtr->Bytes, 0, LogMemoBufPtr->Size);
}
__finally {
delete enc;
}
*/
LogMemo->GoToTextEnd();
LogMemo->SelLength = 0;
// not sure if this is the best replacement for EM_SCROLLCARET...
LogMemo->VScrollBar->Value = LogMemo->VScrollBar->Max;
}
__finally {
LogMemo->Lines->EndUpdate();
}
I have an access table with a memo field where data is entered using a form and before the user enters new data, a date is added in the form of (Apr-01). Upon saving, the new data is added at the top. Then I have a function as follows that goes into the field and gets the newest data so it would be at the top:
Example data
Apr-01 - new data
Mar-09 - old data
etc
Function to get the latest:
Public Function GetLatest(text As String) As String
If (IsNull(text)) Then
GetLatest = ""
Else
Set objRegExpr = New regexp
objRegExpr.Pattern = "([A-Za-z]{3}-[0-9]{2})"
objRegExpr.Global = True
objRegExpr.IgnoreCase = True
Set colMatches = objRegExpr.Execute(text)
del = colMatches(1)
txt = Split(text, del)
GetLatest = txt(0)
End If
End Function
Running this function in the Immediate window, I get the expected results but when I run the same function in a query, I get invalid procedure or argument pointing at this line del = colMatches(1). What am I missing?
To extract what you capture you want the 1st item which is index 0 not 1;
del = colMatches.Item(0)
Or an alternative avoiding the regexp object;
if ucase$(text) like "[A-Z][A-Z][A-Z]-[0-9][0-9]*" then GetLatest = left$(text,6)
I am facing some prob in managed C++, I can fill my ListView , but I am unable to edit specific row at later time
I can fill like
listView1->View = View::Details;
listView1->Columns->Add("S.no",......
ListViewItem^ itmp = gcnew System::Windows::Forms::ListViewItem("100");
ListViewSubItem^ itms1 = gcnew ListViewSubItem(itmp, "12:12:12 PM");
itmp->SubItems->Add(itms1);
listView1->Items->Add(itmp);
I want to implement following VB code in managed C++ , but showing errors
Dim FindlvItem() As ListViewItem // here i am facing problem in conversion to c++ managed
FindlvItem = Me.ListView1.Items.Find("100", False)
FindlvItem(0).SubItems(0).Text = "01:01:01 AM"
I dont want to use foreach loop to save processing
vs.net 2008
You should be able to convert the code almost line for line to C++/CLI. The only problem is that Find will return a collection of list view items, not just a single item.
array<ListViewItem^>^ FindlvItem = ListView1->Items->Find("100",false);
if (FindlvItem->Length == 1)
{
FindlvItem[0]->SubItems[0]->Text = "01:01:01 AM";
} // if found
I need to get the primary key for a row and then insert it into one of the other columns in a string.
So I've tried to do it something like this:
newsObj = new news();
newsObj.name = "test"
newsObj.Save();
newsObj.url = String.Format("blah.aspx?p={0}",newsObj.col_id);
newsObj.Save();
But it doesn't treat it as the same data object so newsObj.col_id always comes back as a zero. Is there another way of doing this? I tried this on another page and to get it to work I had to set newsObj.SetIsLoaded(true);
This is the actual block of code:
page p;
if (pageId > 0)
p = new page(ps => ps.page_id == pageId);
else
p = new page();
if (publish)
p.page_published = 1;
if (User.IsInRole("administrator"))
p.page_approved = 1;
p.page_section = staticParent.page_section;
p.page_name = PageName.Text;
p.page_parent = parentPageId;
p.page_last_modified_date = DateTime.Now;
p.page_last_modified_by = (Guid)Membership.GetUser().ProviderUserKey;
p.Add();
string urlString = String.Empty;
if (parentPageId > 0)
{
urlString = Regex.Replace(staticParent.page_url, "(.aspx).*$", "$1"); // We just want the static page URL (blah.aspx)
p.page_url = String.Format("{0}?p={1}", urlString, p.page_id);
}
p.Save();
If I hover the p.Save(); I can see the correct values in the object but the DB is never updated and there is no exception.
Thanks!
I faced the same problem with that :
po oPo = new po();
oPo.name ="test";
oPo.save(); //till now it works.
oPo.name = "test2";
oPo.save(); //not really working, it's not saving the data since isLoaded is set to false
and the columns are not considered dirty.
it's a bug in the ActiveRecord.tt for version 3.0.0.3.
In the method public void Add(IDataProvider provider)
immediately after SetIsNew(false);
there should be : SetIsLoaded(true);
the reason why the save is not working the second time is because the object can't get dirty if it is not loaded. By adding the SetIsLoaded(true) in the ActiveRecord.tt, when you are going to do run custom tool, it's gonna regenerate the .cs perfectly.